MediaPlayer: stop call in state 4

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

+6
source share
2 answers

I have not tested this myself, but you should be able to reset() MediaPlayer when you are in preparation.

+2
source

Try calling MediaPlayer.prepare () before executing MediaPlayer.stop () when you click the back button (implement the onPause or onStop method)

+1
source

Source: https://habr.com/ru/post/905577/


All Articles