我有一个包含VideoView
的片段和一个视频播放列表。它允许用户单击播放列表中的视频以交换VideoView
的内容。它还允许用户在每个视频周围寻找。在这里发布整个代码是不可行的,但我试图缩小问题,以便我可以添加样本。
我发现如果我快速更改VideoView
的来源并在VideoView
中搜索,我会收到IllegalStateException
:
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x415fe8b0)
E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: java.lang.IllegalStateException
E/AndroidRuntime: at android.media.MediaPlayer.getVideoWidth(Native Method)
E/AndroidRuntime: at android.widget.VideoView$2.onPrepared(VideoView.java:346)
E/AndroidRuntime: at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2048)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:213)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5225)
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
如您所见,我的任何代码都没有引用。如果我慢慢地执行相同的操作,我似乎没有同样的问题。从阅读如下问题:
IllegalStateException calling MediaPlayer.reset()
http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States
我认为当玩家处于无效状态时我正在执行某项操作,但我不知道该操作是什么。我在MediaPlayer.OnErrorListener
上设置了VideoView
,但我没有在日志中看到任何错误。我不会随时在reset
上致电release
或VideoView
。
我用以下内容初始化播放器:
localPlayerVideoView = (VideoView) view.findViewById(R.id.player)
MediaController mediaController = new MediaController(getActivity());
mediaController.setVisibility(View.GONE);
mediaController.setAnchorView(localPlayerVideoView);
localPlayerVideoView.setMediaController(mediaController);
localPlayerVideoView.setVideoPath(file.getAbsolutePath());
localPlayerVideoView.setOnPreparedListener(localOnPreparedListener);
localPlayerVideoView.setOnErrorListener(localOnErrorListener);
localPlayerVideoView.setOnInfoListener(localOnInfoListener);
localPlayerVideoView.requestFocus();
准备好了:
localPlayerVideoView.seekTo(time);
localPlayerVideoView.start();
交换视频:
localPlayerVideoView.setOnPreparedListener(null);
localPlayerVideoView.setPlayPauseListener(null);
localPlayerVideoView.suspend();
localPlayerVideoView.setVideoPath(file.getAbsolutePath());
localPlayerVideoView.setOnPreparedListener(localOnPreparedListener);
localPlayerVideoView.setPlayPauseListener(localPlayPauseListener);
localPlayerVideoView.requestFocus();
寻求视频:
localPlayerVideoView.seekTo(time);
localPlayerVideoView.pause();
在崩溃发生之前,我已经记录了这些是我调用的VideoView
函数:
setOnPreparedListener(null)
setPlayPauseListener(null)
suspend
setVideoPath
setOnPreparedListener
setPlayPauseListener
requestFocus
onPrepared
onPlaying
getCurrentPosition
onPlaying
getCurrentPosition
getCurrentPosition
onInfo: what: 3
canPause
pause
setOnPreparedListener(null)
setPlayPauseListener(null)
suspend
setVideoPath
setOnPreparedListener
setPlayPauseListener
requestFocus
onPrepared
onPlaying
getCurrentPosition
canPause
pause
canPause
pause
setOnPreparedListener(null)
setPlayPauseListener(null)
suspend
setVideoPath
setOnPreparedListener
setPlayPauseListener
requestFocus
我如何追踪此错误?