10

I am using a VideoView to play a video file kept in res/raw. I couldnt find a way to control the playback speed of the video. Basically i want to reduce and increase the playback while moving a scroll bar. Is there any work around for implementing this?

1
  • hi, i want to implement like you in video view functionality, i did't get any idea, if you have find any solution for this please send me, Thanks.
    – Hasmukh
    Sep 25, 2012 at 7:25

5 Answers 5

16

you can use this but it works on api 23 and above

 mVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {

            //works only from api 23
            PlaybackParams myPlayBackParams = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                myPlayBackParams = new PlaybackParams();
                myPlayBackParams.setSpeed(0.8f); //you can set speed here
                mp.setPlaybackParams(myPlayBackParams);
            }

        }
    });
2
  • brief coding, excelent Jul 7, 2020 at 20:31
  • can guarantee this works than using mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed));
    – harveyhans
    Feb 23, 2021 at 13:37
4

No, you cannot change the playback rate by simply using VideoView. VideoView and MediaPlayer only provide limited media functions.

You have to use some third party library, e.g., PVPlayer, and implement that yourself.

That's also why good media players on Android are so valuable:)

0
2

I want to say than Mk Kamal's solution have an unexpected side effect: calling setPlaybackParams in OnPreparedListener will force VideoView to repeat the latest played video when the app was returned from the background. I don't know is it a bug or a feature, but I found a way to avoid such behavior:

private float speed = 0.8f;
private final MediaPlayer.OnInfoListener listener = (mp, what, extra) -> {

    if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
        mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed));
        return true;
    }
    return false;
};


videoView.setOnPreparedListener(
                mp -> {
                    mp.setOnInfoListener(listener);
                }
        );

MEDIA_INFO_VIDEO_RENDERING_START will be sent only if the palyer was already started.

And I want to emphasize that getPlaybackParams is annotated as @NonNull, so it's not necessary to create a new PlaybackParams object.

0

Kotlin variant, API above 23

val playerView = itemView.findViewById<VideoView>(R.id.videoview)
playerView.setVideoURI(Uri.parse("android.resource://" + context.packageName + "/" + R.raw.123.mp4))

playerView.setOnPreparedListener { mediaPlayer ->
   playerView.seekTo(1) // for video preview
   mediaPlayer.playbackParams = mediaPlayer.playbackParams.apply {
      speed = 0.6f
   }
   playerView.start()
}
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 15, 2022 at 0:24
-3

DicePlayer works perfectly on my Asus Transformer. It has a speed control onscreen display.

I'm not sure what res/raw is though.

1
  • 3
    Question was about implementing speed control in android, not about existing apps. Therefor deserved negative points
    – Ewoks
    Sep 3, 2015 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.