I have an activity that has a VideoView that asynchronously prepares 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 being "cooked", I show ProgressDialog ... if I press the "Back" button during this state, the following error message will be printed in ADB and the action will quietly work with a short wait on 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 VideoView from preparing a video so you can exit it?
Note. I do not have access to the actual MediaPlayer object until the callback for the finished video is called:
@Override public void onPrepared(MediaPlayer player)
... which did not happen when the MediaPlayer / VideoView "cooked up."
source share