Git Product home page Git Product logo

trimmy's Introduction

This code is built on top of VideoTrimmer.

Changes from original:

  1. The UI for time selector info is modified.
  2. The range selector is forced to begin from 00:00. In the original the range bar was positioned in the center.
  3. The library used to trim the video is changed to MP4Composer from MP4Parser.
  4. VideoTrimmerView is moved into the library for quick and easy setup.
  5. Fixed TimeLineView not getting updated issue when a new video is loaded again.
  6. Added watermark functionality.

Gradle

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>'
}

How to use

  1. Add VideoTrimmerView in your layout.
 <com.amp.trimmy.VideoTrimmerView
        android:id="@+id/videoTrimmerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
  />
  1. 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)
  1. 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() {

    }

}

trimmy's People

Contributors

amal92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mohanrajsambath

trimmy's Issues

Crash when calling initiateTrimming() for some videos

NOTE: I'm using 1.0.6 version

In my app, I make the user either record a video inside the app or choose an existing video from the gallery. Then I transfer the video Uri to my TrimActivity where I use your library.

To get the video by recording I used this library .
Once I record the video, I get the Uri and I use it in your library, and the trimming works without any issues.

But to get the video from the gallery I use a different library.
And once I choose a video file from the video-picker library, I use the Uri in your library it plays the video without any issues, but when I call initiateTrimming() it crashes.!!

The crash error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ibtikarat.goltlak, PID: 3819
    kotlin.KotlinNullPointerException
        at com.amp.trimmy.BaseVideoTrimmerView.initiateTrimming(BaseVideoTrimmerView.kt:232)
        at com.ibtikarat.goltlak.ui.general.ChooseMediaActivity.onCreate$lambda-2$lambda-0(ChooseMediaActivity.kt:69)
        at com.ibtikarat.goltlak.ui.general.ChooseMediaActivity.$r8$lambda$XL6XwGMFVLdhKJLsTVcaf3cgUPM(Unknown Source:0)
        at com.ibtikarat.goltlak.ui.general.ChooseMediaActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27336)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

I don't know where the issue is, because the Uri I get from the video-picker library seems to be valid and your library plays the video without any issues, only when calling initiateTrimming() the crash occurs.

The video file Uri log

E/>>>: --> uri path = /storage/emulated/0/Download/SampleVideo_1280x720_5mb.mp4

Error inflating class com.amp.trimmy.VideoTrimmerView

When I was facing issue #1 I tried to import the library as a module so I can try to debug the issue myself.

implementation project(path: ':video_trimmer_library')


But once I open the activity that has the VideoTrimmerView it crashes. Although this crash did not occur when I downloaded the library normally as a dependency like this implementation 'com.github.Amal92:Trimmy:1.0.6'

The crash error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ibtikarat.goltlak, PID: 6484
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ibtikarat.goltlak/com.ibtikarat.goltlak.ui.general.ChooseMediaActivity}: android.view.InflateException: Binary XML file line #20 in com.ibtikarat.goltlak:layout/activity_choose_media: Binary XML file line #20 in com.ibtikarat.goltlak:layout/activity_choose_media: Error inflating class com.amp.trimmy.VideoTrimmerView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #20 in com.ibtikarat.goltlak:layout/activity_choose_media: Binary XML file line #20 in com.ibtikarat.goltlak:layout/activity_choose_media: Error inflating class com.amp.trimmy.VideoTrimmerView
     Caused by: android.view.InflateException: Binary XML file line #20 in com.ibtikarat.goltlak:layout/activity_choose_media: Error inflating class com.amp.trimmy.VideoTrimmerView
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:854)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at com.ibtikarat.goltlak.databinding.ActivityChooseMediaBinding.inflate(ActivityChooseMediaBinding.java:60)
        at com.ibtikarat.goltlak.databinding.ActivityChooseMediaBinding.inflate(ActivityChooseMediaBinding.java:54)
        at com.ibtikarat.goltlak.ui.general.ChooseMediaActivity.onCreate(ChooseMediaActivity.kt:43)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference
E/AndroidRuntime:     at com.amp.trimmy.VideoTrimmerView._$_findCachedViewById(Unknown Source:6)
        at com.amp.trimmy.VideoTrimmerView.getRangeSeekBarView(VideoTrimmerView.kt:46)
        at com.amp.trimmy.BaseVideoTrimmerView.<init>(BaseVideoTrimmerView.kt:86)
        at com.amp.trimmy.VideoTrimmerView.<init>(VideoTrimmerView.kt:16)
        at com.amp.trimmy.VideoTrimmerView.<init>(VideoTrimmerView.kt:12)
        at com.amp.trimmy.VideoTrimmerView.<init>(Unknown Source:16)
        	... 27 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.