11

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();}
    }
});
VC.One
  • 14,790
  • 4
  • 25
  • 57
user2306482
  • 121
  • 1
  • 5
  • 1
    What is the problem exactly? Does speed setting of `1.f` work properly (since **1.0** is normal speed) or you get error message? Try : `mp.setPlaybackParams(new PlaybackParams().setSpeed(2.5));` What happens...? – VC.One Nov 06 '17 at 14:53

3 Answers3

4

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));
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Rainmaker
  • 10,294
  • 9
  • 54
  • 89
2

After many try i find a solution.

Example how use VideoView

final VideoView mVideoView = findViewById(R.id.videoView);
mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/bluetooth/test.webm"); //Path of your file video
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
    @Override
    public void onPrepared(MediaPlayer mp)
    {
        mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(0.55f));
        mVideoView.start();
    }
});
MediaController media = new MediaController(this); //this is for play and restart play manually
media.setAnchorView(mVideoView);
mVideoView.setMediaController(media);
//mVideoView.start();
Crammeur
  • 678
  • 7
  • 17
0

You have not started the Media Playe..

Try This Code:

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

  
}
Yahya M
  • 392
  • 3
  • 13