I'm using a VideoView component to play videos. I can't seem to clear the VideoView display after I manually invoke stopPlayback(). I would like to reset the VideoView so that the original background is visible.
- Play a video in a VideoView component.
- Select a new video to play.
- The VideoView is stuck on the last frame of the first video until the next video starts. If there is an error with the next video, the static image from the first video remains stuck there.
- If I let the video play to completion state, the display is cleared.
The code I'm using:
private VideoView videoViewer = null;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
if (videoViewer != null) {
videoViewer.setOnPreparedListener(new OnPreparedListener());
}
...
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (videoViewer != null) {
videoViewer.stopPlayback();
videoViewer.setVideoURI(Uri.parse("http://my_vido_url/playlist.m3u8"));
}
}
private class OnPreparedListener implements MediaPlayer.OnPreparedListener {
@Override
public void onPrepared(MediaPlayer mp) {
videoViewer.start();
}
}
Note that based on the VideoView.java source, stopPlayback() takes the following action on the underlying MediaPlayer:
public void stopPlayback() {
if (mMediaPlayer != null) {
mMediaPlayer.stop();
mMediaPlayer.release();
mMediaPlayer = null;
}
}