5

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.

Papajohn000
  • 809
  • 1
  • 16
  • 32
  • Did you ever get this resolved? – spitzanator Sep 03 '13 at 14:06
  • Nope I haven't.The only thing I could think of is using ffmpeg to copy the first frame multiple times and add it to the beginning of the video. That just a theory though haven't gone through with it. – Papajohn000 Sep 04 '13 at 20:21

2 Answers2

2

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.

weston
  • 54,145
  • 21
  • 145
  • 203
0

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.

Community
  • 1
  • 1
Josha
  • 579
  • 3
  • 7