This code is built on top of VideoTrimmer.
- The UI for time selector info is modified.
- The range selector is forced to begin from 00:00. In the original the range bar was positioned in the center.
- The library used to trim the video is changed to MP4Composer from MP4Parser.
- VideoTrimmerView is moved into the library for quick and easy setup.
- Fixed TimeLineView not getting updated issue when a new video is loaded again.
- Added watermark functionality.
Step 1: Add the JitPack repository to your root build file.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2: Add the dependency:
dependencies {
implementation 'com.github.Amal92:Trimmy:<latest-version>'
}
- Add VideoTrimmerView in your layout.
<com.amp.trimmy.VideoTrimmerView
android:id="@+id/videoTrimmerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
- Use the following methods to use VideoTrimmerView
videoTrimmerView.setMaxDurationInMs(10 * 1000)
videoTrimmerView.setMinDurationInMs(1 * 1000)
videoTrimmerView.setOnK4LVideoListener(this)
videoTrimmerView.setDestinationFile(trimmedVideoFile)
// make sure the videoTimmerView is drawing before calling this method
videoTrimmerView.post {
videoTrimmerView.setVideoURI(inputVideoUri)
}
// Use this is control the visibility of time duration displayed
videoTrimmerView.setVideoInformationVisibility(true)
// Use this to set if the trimmed video should be mute
videoTrimmerView.shouldMute(true) // Default is false
// Use this to set the time scale of the trimmed video
// Value should be in the range of -8(X) to 8(X)
videoTrimmerView.setTimeScale(2) // Default is 1
// Use this method to start trimming the selected time frame
videoTrimmerView.initiateTrimming()
// Use this method to draw watermark on the trimmed video
videoTrimmerView.setWaterMark(BitmapFactory.decodeResource(resources, R.drawable.text_logo),WaterMarkPosition.RIGHT_BOTTOM,20,20)
- Implement the listener to receive callback
class MainActivity : AppCompatActivity(), VideoTrimmingListener {
override fun onErrorWhileViewingVideo(what: Int, extra: Int) {
}
override fun onFinishedTrimming(uri: Uri?) {
// use this uri to the trimmed video file
}
override fun onTrimFailed(exception: Exception?) {
}
override fun onTrimProgressing(progress: Double) {
}
override fun onTrimStarted() {
}
override fun onVideoPrepared() {
}
}