I have a video player that gets reset and loaded with a new video in one activity. One of the problems I had with this approach was that the last frame of the previous window was still shown when the next video is loaded. Several people have the same issue.
I solved this by doing the following in the onCompletion
listener, similar to what is explained in this question and this other one:
mPlayer.stop();
mPlayer.release();
Canvas canvas = mPlayView.getHolder().lockCanvas();
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
mPlayView.getHolder().unlockCanvasAndPost(canvas);
mPlayer = null;
Then later, I call this again:
mPlayer = new MediaPlayer();
mPlayer.setDataSource(videoPath);
mPlayer.setDisplay(mSurfaceHolder);
mPlayer.setScreenOnWhilePlaying(true);
mPlayer.setOnPreparedListener(this);
mPlayer.setOnCompletionListener(this);
mPlayer.setOnVideoSizeChangedListener(this);
mPlayer.setOnErrorListener(this);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepare();
// wait for onPrepared callback and play
The problem is that the video play surface is still blackāno video is shown anymore.
How do I "reset" the canvas and make it show the video again?
Or if that does not work, how do I clear the canvas of the last frame instead? I tried this but the next loaded video still shows the last frame of the previous one.