I have an activity that has a VideoView that is asynchronously preparing a video:
Uri mUri = "uri to streaming video"
VideoView mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
mVideoView.setOnErrorListener(this);
mVideoView.setOnCompletionListener(this);
mVideoView.setVideoURI(mUri);
mVideoView.setMediaController(null);
mVideoView.setOnPreparedListener(this);
While it is "preparing" I show a ProgressDialog... if I press the back button during this state the following error is printed to ADB and the activity crashes silently with a short wait at a black screen:
E/MediaPlayer( 2204): stop called in state 4
E/MediaPlayer( 2204): error (-38, 0)
W/ActivityManager( 59): Activity pause timeout for HistoryRecord{45080368 com.myapp.VideoPlayerActivity}
What is the best way to stop a VideoView from preparing a video so you can exit an activity?
Note: I don't have access to the actual MediaPlayer object until the callback for the video being prepared is called:
@Override
public void onPrepared(MediaPlayer player)
... which hasn't happened while the MediaPlayer/VideoView is "preparing".
I have not tested it my self but you should be able to reset()
the MediaPlayer when you are in preparing state.
Try calling MediaPlayer.prepare() before doing MediaPlayer.stop() when back button is pressed (implement onPause or onStop activity method)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With