Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer: stop called in state 4

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".

like image 419
NPike Avatar asked Jan 10 '12 00:01

NPike


2 Answers

I have not tested it my self but you should be able to reset() the MediaPlayer when you are in preparing state.

like image 99
tidbeck Avatar answered Nov 15 '22 03:11

tidbeck


Try calling MediaPlayer.prepare() before doing MediaPlayer.stop() when back button is pressed (implement onPause or onStop activity method)

like image 29
frayab Avatar answered Nov 15 '22 05:11

frayab