I have created a media player which plays video on the surface view. After completion of video the last frame of the video remains on the surface. I want to remove the video frame from the surface because after some delay another video starts.
The flow of the video is:
NOW: Video on surface -> last video frame on surface -> another video on surface.
But the required flow is:
REQUIRED: Video on surface -> clear surface (black) -> another video on surface.
can anyone help to solve this problem.
Thanks Ishan jain
You can clear it with GLES. You can't clear it with
Canvas
draw commands because that will prevent you from playing movies on that surface again.An example can be found in Grafika's PlayMovieSurfaceActivity class. The
clearSurface()
method does this:The
EglCore
andWindowSurface
classes are part of Grafika. The key thing is that it attaches to the surface, does the clear, and then detaches from the surface. Make sure the video player has released the surface before doing this, or GLES won't be able to attach.If you want to understand why the attach / detach stuff is necessary, see the system-level graphics architecture doc.
I had a similar issue. In my case, I was showing a title card that completely covered the video view followed by the video itself. The first title card and video that followed played fine. However, when any subsequent title card was hidden, the last frame of the previous video would flash before the next video started. I added an info listener to my VideoView to listen for the first frame render before hiding the title card. This covers up the video until the first correct frame has rendered. I hope this helps!
Clear surface when playback of video is completed (MediaPlayer onCompletion callback):
Another option (but I don't remember clearly right now) is call one of MediaPlayer class function when onComplition() callback called:
One of them cause clear surface view. After
release()
you have to create anotherMediaPlayer
instance again.I have a sample problem and i fixed it by using these two lines after player release.
surfaceViewHolder.setFormat(PixelFormat.TRANSPARENT); surfaceViewHolder.setFormat(PixelFormat.OPAQUE);
I have the same problem. Maybe help someone. I found solution here https://stackoverflow.com/a/18906637
I have player in Service, in Fragment I have onComplete callback and after video finished:
Building on Fadden's answer, and Andreimarinescu's question, here is a version for API 16 and below:
Pretty crude, lacks error checking, but it works for me.