Playback video in slow motion in android
Asked Answered
B

2

6

- 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......

Brainpan answered 30/8, 2013 at 6:25 Comment(0)
R
6

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.
                }
        });
Rival answered 10/8, 2017 at 11:55 Comment(0)
S
0

If you are searching how to embedded VLC into android, you can ref to this. and you can change the speed by calling setRate(0.5f) to libVLC for slow motion.

Sesquicarbonate answered 15/3, 2014 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.