Skip to content

Conversation

@donovanfm
Copy link
Contributor

@donovanfm donovanfm commented Apr 18, 2025

Add video trimming to VideoEditScreen in SociaLite.

Given the growing number of edit options, this PR also splits out the editing controls into "Edit", "Overlay", and "Trim" tabs.

Use a RangeSlider to allow user to specify a start point and end point for trimming a recently recorded video.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @donovanfm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request adds video trimming functionality to the VideoEditScreen. It introduces a RangeSlider that allows users to specify the start and end points for trimming a recently recorded video. The changes involve modifications to the UI to incorporate the RangeSlider and update the VideoEditScreenViewModel to handle the trimming logic.

Highlights

  • Video Trimming: Implements video trimming using a RangeSlider in the VideoEditScreen.
  • UI Updates: Updates the UI to include the RangeSlider for specifying the start and end points of the video trim.
  • ViewModel Changes: Modifies the VideoEditScreenViewModel to incorporate the video trimming parameters when processing the video.

Changelog

Click here to see the changelog
  • app/src/main/java/com/google/android/samples/socialite/ui/Main.kt
    • Adds @file:OptIn(ExperimentalMaterial3Api::class) to enable experimental Material 3 APIs.
    • Adds @OptIn(ExperimentalMaterial3Api::class) annotation to the MainNavigation composable function.
  • app/src/main/java/com/google/android/samples/socialite/ui/videoedit/VideoEditScreen.kt
    • Imports RangeSlider and RangeSliderState from Material 3.
    • Adds videoDuration, videoTrimStart, and videoTrimEnd states to the VideoEditScreen composable.
    • Adds a RangeSlider to allow users to select the start and end points for video trimming.
    • Passes videoTrimStart and videoTrimEnd to the VideoMessagePreview composable.
    • Retrieves video duration using MediaMetadataRetriever and updates the videoDuration and videoTrimEnd states.
    • Modifies VideoMessagePreview to accept duration and trimEnd parameters.
    • Adds @OptIn(ExperimentalMaterial3Api::class) annotation to VideoEditScreen and VideoEditScreenPreview composables.
  • app/src/main/java/com/google/android/samples/socialite/ui/videoedit/VideoEditScreenViewModel.kt
    • Adds videoTrimStart and videoTrimEnd parameters to the editVideo function.
    • Uses MediaItem.ClippingConfiguration to set the start and end positions for video trimming in the editedMediaItem.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A slider's gentle sway,
A video finds its way,
Trimmed with care and grace,
A perfect, concise space,
For stories to convey.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Human note: these AI review comments have been addressed)

Code Review

The pull request introduces video trimming functionality to the VideoEditScreen using a RangeSlider. This allows users to specify start and end points for trimming recorded videos. The changes seem well-structured and integrate smoothly with the existing UI components. However, there are a few areas that could be improved for better clarity and efficiency.

Summary of Findings

  • Inconsistent Unit Handling: The code mixes milliseconds and seconds when displaying and handling video trim values. Standardizing on one unit (preferably milliseconds internally for precision) would reduce potential confusion and errors.
  • Potential for UI Jitter: Updating videoTrimEnd.value directly within the onValueChange lambda of the RangeSlider might cause UI jitter, especially on slower devices. Consider debouncing or throttling the updates to improve performance.
  • Missing Error Handling: The code doesn't handle potential errors when extracting video metadata. Adding error handling would make the application more robust.

Merge Readiness

The pull request introduces a valuable feature, but there are a few issues that should be addressed before merging. Specifically, the inconsistent unit handling and potential UI jitter should be resolved to ensure a smooth user experience. The missing error handling should also be addressed to improve the robustness of the application. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Human note: these AI review comments have been addressed)

Code Review

This pull request introduces a video trimming feature using a RangeSlider, which is a great addition. The UI for editing controls has been nicely refactored into a tabbed layout, improving organization. I've found a couple of critical resource leaks related to MediaMetadataRetriever not being released, which could cause crashes. I've also suggested improvements to simplify state management in VideoEditScreen and to correct the video duration handling in the VideoEditScreenViewModel for more robust processing. Please take a look at the detailed comments.

val duration = rememberSaveable { mutableLongStateOf(0L) }

LaunchedEffect(uri) {
val mediaMetadataRetriever = MediaMetadataRetriever()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amanc3765, this will be a good sample to update with the new Media3 APIs when you have a chance!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for flagging this, Nevin!

@donovanfm donovanfm merged commit b6fed0d into android:main Sep 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants