I have a snippet containing a VideoView and a video playlist. This allows the user to click the video in the playlist to change the contents of the VideoView . It also allows the user to search all videos. It is not possible to post all the code here, but I'm trying to narrow down the problem to add a sample.
I find that if I quickly change the source of the VideoView and search in the VideoView , I get an 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)
As you can see, there is no link to any of my codes. If I follow the same steps slowly, I don't seem to have the same problem. From reading questions such as:
IllegalStateException throws MediaPlayer.reset ()
http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States
I assume that I am performing the action when the player is in an invalid state, but I do not know what the action is. I have a MediaPlayer.OnErrorListener installed on a VideoView , but I don't see errors in the logs. I do not call reset or release on the VideoView anywhere.
I initialize the player with:
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();
Prepared by:
localPlayerVideoView.seekTo(time); localPlayerVideoView.start();
Video sharing:
localPlayerVideoView.setOnPreparedListener(null); localPlayerVideoView.setPlayPauseListener(null); localPlayerVideoView.suspend(); localPlayerVideoView.setVideoPath(file.getAbsolutePath()); localPlayerVideoView.setOnPreparedListener(localOnPreparedListener); localPlayerVideoView.setPlayPauseListener(localPlayPauseListener); localPlayerVideoView.requestFocus();
Watch the video:
localPlayerVideoView.seekTo(time); localPlayerVideoView.pause();
Just before the crash, I wrote that these are the VideoView functions that I call:
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
How can I track this error?