0

I am designing an android video editor app and one of the feature is to trim video, selected from gallery. I can give an option to select the range using the RangeSlider, displayed at the bottom of the VideoView, to the user and then use FFMPEG library to trim the video.

But i am not able to show the progress of the video being played, within the selected range, on the RangeSlider.

Not sure if i am approaching properly, hence please provide me a solution to achieve this.

Suman Mondal
  • 47
  • 1
  • 6

1 Answers1

4

When you change the bounds of the RangeSlider, you need to calculate the startTime and endTime of the video. Once you are able to calculate the startTime and endTime, you need to create a ClippingMediaSource instance.

public ClippingMediaSource(MediaSource mediaSource, long startPositionUs, long endPositionUs)

ClippingMediaSource takes three paramters:

  • MediaSource
  • startPositionUs
  • endPositionUs

You can create media source by following the below snippet:

fun getMediaSource(file: String): MediaSource {
        return ProgressiveMediaSource.Factory(DefaultDataSourceFactory(context, userAgent))
            .createMediaSource(MediaItem.fromUri(Uri.parse(file)))
    }

After creating the MediaSource you can pass on the values for start and end time you had calculated.

Note: startPositionUs and endPositionUs are in micro-seconds.

Once done, you can pass this media source to your ExoPlayer and it will play only the selected/trimmed part of your video.