Android 6.0 - 使用PlaybackParams设置视频速度

时间:2015-10-12 03:23:28

标签: java android video android-mediaplayer video-processing

我在如何实施PlaybackParams来设置视频速度方面存在问题:

  

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

     

在API级别23中添加了    使用PlaybackParams获取播放速率。

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

        if (mPlaybackState == PlaybackState.PLAYING) { mVideoView.start();}
    }
});
  

退货
  正在使用的播放速率。
  引发IllegalStateException
  如果内部同步引擎或音频轨道尚未初始化。

这是我的代码:

private Locale getCurrentLocal( HttpServletRequest request )
{
    String localeParameter = request.getParameter( "lang" );
    if (!StringUtil.isEmpty( localeParameter ))
    {
        return org.springframework.util.StringUtils.parseLocaleString( localeParameter );
    }
    else
    {
        return localeResolver.resolveLocale( request );
    }
}

3 个答案:

答案 0 :(得分:4)

您在调用'setPlayParams'方法时遇到IllegalStateException,因为您没有执行PlaybackParams params = \ tmp.getPlaybackParams(),设置速度然后将其传递给mp.setPlaybackParams()!在调用mp.getPlayParams()!

时直接设置速度
MediaPlayer mp = ...; 
float speed = 0.55f;     
mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed));

答案 1 :(得分:2)

经过多次尝试,我找到了解决方案。

示例如何使用 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();

答案 2 :(得分:0)

您尚未启动 Media Playe..

试试这个代码:

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

  
}