Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 6.0 - Set video speed with PlaybackParams

I have problems about how to implement PlaybackParams to set video speed:

public PlaybackParams getPlaybackParams ()

Added in API level 23
Gets the playback rate using PlaybackParams.

PlaybackParams setSpeed (float speed) //Sets the speed factor.

Returns:
the playback rate being used.
Throws IllegalStateException:
if the internal sync engine or the audio track has not been initialized.

This is my code:

mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() 
{
    @Override
    public void onPrepared(MediaPlayer mp) 
    {
        mp.setPlaybackParams(new PlaybackParams().setSpeed(1.f));

        if (mPlaybackState == PlaybackState.PLAYING) { mVideoView.start();}
    }
});
like image 388
user2306482 Avatar asked Oct 12 '15 03:10

user2306482


Video Answer


1 Answers

You are getting an IllegalStateException while calling the 'setPlayParams' method, because you're not doing PlaybackParams params = mp.getPlaybackParams(), set the speed and then pass it to mp.setPlaybackParams()! Set the speed DIRECTLY while calling the mp.getPlayParams()!

MediaPlayer mp = ...; 
float speed = 0.55f;     
mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed));
like image 127
Rainmaker Avatar answered Oct 05 '22 23:10

Rainmaker