gpt4 book ai didi

android - MediaPlayer setPlaybackParams 崩溃

转载 作者:太空狗 更新时间:2023-10-29 15:28:07 25 4
gpt4 key购买 nike

当我尝试更改 MediaPlayer 的播放参数时,我的应用程序崩溃了。我不确定为什么会这样。

这是我用来改变播放速度的代码。

PlaybackParams params = new PlaybackParams().allowDefaults();
params.setSpeed(mPlaybackRate.getValue());
mMediaPlayer.setPlaybackParams(params);

在这种情况下,mPlaybackRate.getValue() 返回 1.25f

这是崩溃日志:

08-02 21:09:35.184 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hackmodford.bigfinish, PID: 30986
java.lang.IllegalStateException
at android.media.MediaPlayer.setPlaybackParams(Native Method)
at com.hackmodford.bigfinish.mediaPlayerService.MediaPlayerService.incrementPlaybackRate(MediaPlayerService.java:543)
at com.hackmodford.bigfinish.mediaPlayerService.MediaPlayerService.access$1000(MediaPlayerService.java:47)
at com.hackmodford.bigfinish.mediaPlayerService.MediaPlayerService$3.onCustomAction(MediaPlayerService.java:336)
at android.support.v4.media.session.MediaSessionCompat$Callback$StubApi21.onCustomAction(MediaSessionCompat.java:832)
at android.support.v4.media.session.MediaSessionCompatApi21$CallbackProxy.onCustomAction(MediaSessionCompatApi21.java:231)
at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

最佳答案

您必须确保您的 mediaPlayer 已准备就绪!所以你可以尝试像这样设置一个监听器:

mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
public void onPrepared(MediaPlayer var1) {
PlaybackParams params = mMediaPlayer.getPlaybackParams();
params.setSpeed(3.0f);
mMediaPlayer.setPlaybackParams(params);
}
});

它对我有用。

关于android - MediaPlayer setPlaybackParams 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com