gpt4 book ai didi

android - java.lang.IllegalStateException 是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 22:15:25 26 4
gpt4 key购买 nike

我正在开发一个视频应用程序。第一个视频播放完成后,在“OnCopletion”中我试图开始一个新的。但它只是停止(而不是崩溃)并且什么都不做。在日志中:

10-19 09:44:49.056: ERROR/MediaPlayer(4654): setDataSource called in state 128
10-19 09:44:49.056: WARN/System.err(4654): java.lang.IllegalStateException
10-19 09:44:49.056: WARN/System.err(4654): at android.media.MediaPlayer.setDataSource(Native Method)
10-19 09:44:49.056: WARN/System.err(4654): at ru.osiris.BusAdvertising.BusAdvertisingActivity.onCompletion(BusAdvertisingActivity.java:1255)
10-19 09:44:49.056: WARN/System.err(4654): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1304)
10-19 09:44:49.056: WARN/System.err(4654): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 09:44:49.056: WARN/System.err(4654): at android.os.Looper.loop(Looper.java:123)
10-19 09:44:49.056: WARN/System.err(4654): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-19 09:44:49.056: WARN/System.err(4654): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 09:44:49.056: WARN/System.err(4654): at java.lang.reflect.Method.invoke(Method.java:521)
10-19 09:44:49.056: WARN/System.err(4654): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-19 09:44:49.056: WARN/System.err(4654): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-19 09:44:49.056: WARN/System.err(4654): at dalvik.system.NativeStart.main(Native Method)

这是什么意思?我该如何解决?有我的代码:

public class BusAdvertisingActivity extends Activity implements LocationListener, OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
...
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private Bundle extras;

@Override
public void onCreate(Bundle icicle) {
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo();
}
private void playVideo(Integer Media) {
Log.d(TAG, "playVideo called");
doCleanUp();
try {
File clip=new File(Environment.getExternalStorageDirectory(),
playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");
path = clip.getAbsolutePath();
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);


} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
}


public void onCompletion(MediaPlayer arg0) {

Log.d(TAG, "onCompletion called");
FLcurrentVideo++;

File clip=new File(Environment.getExternalStorageDirectory(),
playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");
path = clip.getAbsolutePath();

try {
Log.d ("111", path);
arg0.setDataSource(clip.getAbsolutePath()); //I got exception here
arg0.setDisplay(holder);
arg0.prepare();
arg0.setOnBufferingUpdateListener(this);
arg0.setOnCompletionListener(this);
arg0.setOnPreparedListener(this);
arg0.setOnVideoSizeChangedListener(this);
arg0.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

请帮帮我。

最佳答案

如果您看到此状态图(取自 https://developer.android.com/reference/android/media/MediaPlayer.html#StateDiagram):enter image description here

你会意识到你应该调用 reset() 让它回到空闲状态。只有这样你才能调用 setDataSource()

关于android - java.lang.IllegalStateException 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7816551/

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