Reputation: 839
I'm trying to create an custom view that has a Mediaplayer tied into it. What I want to happen is that once the first frame is rendered on the screen the MediaPlayer will pause for a second or two then finish up the video. I'm having a problem trying to figure out when that first frame comes on the screen. I've tried using:
MediaPlayer.start() then right after Mediaplayer.pause() - this doesn't work because the system needs time to load the video and the screen is black when I do this.
OnBufferingUpdateListener - doesn't work because it only applies to videos from the internet
OnInfoListener MEDIA_INFO_VIDEO_RENDERING_START - the API is 17 and that's too high.
onDraw in custom view - currently testing, I'm not sure how to know when the video frames are being drawn.
What i'm currently doing is setting up a timer in my code to wait like 50 milliseconds then once the timer is done pause the video for a certain amount of time. However, this is just a quick fix and not a long term solution.
I feel the only way to solve this problem is by setting up some sort of custom listener or by using a method that is called once the video frames come on screen. However, my problem is I don't know what to listen for and I haven't found a method that is called when the video starts playing. So any help in solving this problem would be much appreciated.
Upvotes: 5
Views: 3338
Reputation: 599
I had a similar requirement (min API lvl 15, show first frame and then pause).
I ended up using the answer from https://stackoverflow.com/a/17450763/968451 and adding a bit of code to the onSurfaceTextureUpdated
method to pause the MediaPlayer
with the first call.
Upvotes: 0
Reputation: 54801
You're correct that:
mediaPlayer.start();
mediaPlayer.pause();
Does not stop on the first frame.
mediaPlayer.seek(0);
Updates and displays the first frame, and leaves it in a paused state.
Upvotes: 2