Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playback video in slow motion in android

- I am working on a project which needs to play video in slow motion.

- I am well aware that Android doesn't provide these functionality.

- I found PVPlayer Engine and libVLC which possessed these capabilities, but i didn't found any tutorial or proper documentation of including them in the android project and using them.

- So i tried doing this by using Runnable and Handler, it was successful in slowing down the video but they possessed jerks during playing.

public class MainActivity extends Activity {

    VideoView vx;
    Button mbutt;
    Handler h ;
    int curr = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        h = new Handler();

        vx = (VideoView)findViewById(R.id.videoView);
        mbutt = (Button)findViewById(R.id.button_Play);

        vx.setVideoPath("/mnt/sdcard/you.mp4");

        mbutt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                vx.start();
            }
        });


        Runnable r = new Runnable() {

            @Override
            public void run() {

                if (vx != null) {

                    if (vx.isPlaying()){

                        vx.pause();  
                    }
                    else{                        
                        vx.start(); 
                    }
                }

                h.postDelayed(this, 50);
            }
        };

        h.postDelayed(r, 200);






    }


}

- I have tried various combination of pause time and playing time to remove the jerks but all in vain, can anyone help me in removing these jerks so it plays a nice slow motion video or suggest another easy to integrate library into my android project.

Thanks in advance......

like image 357
Kumar Vivek Mitra Avatar asked Aug 30 '13 06:08

Kumar Vivek Mitra


People also ask

Why are all my videos playing in slow motion Android?

It is possible that your video files are corrupt. One of the common reasons behind video playing in slow motion is corruption in your video files. Sometimes these files throw an error displaying the corruption issue and sometimes it affects the videos by lowering its quality, color, or even playing speed.

Can we convert slow motion video to normal in Android?

Launch the Google Photos app on your Android phone, and find the slo-mo video to speed up and tap to view. Tap the Edit button at the bottom of the screen to trigger the speed controller. Now, you can change slow-motion videos to normal speed on Android by pulling the slider.


1 Answers

I am late but I found a solution for API 23 and above. Android 6.0 added PlaybackParams class to control playback behavior. -

Use setPlaybackParams method of MediaPlayer as given below -

videoview = (VideoView)findViewById(R.id.videoview);
videoview.setVideoURI("Your Video URI"); 
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    //works only from api 23
                    PlaybackParams myPlayBackParams = new PlaybackParams();
                    myPlayBackParams.setSpeed(0.5f); //here set speed eg. 0.5 for slow 2 for fast mode
                    mp.setPlaybackParams(myPlayBackParams);

                    videoview.start();//start your video.
                }
        });
like image 64
karanatwal.github.io Avatar answered Sep 18 '22 16:09

karanatwal.github.io