0

I wrote a video play view, it is a SurfaceView with a MediaPlayer instance. I attached the mediaplayer to the surface holder when surface created then start the play.

This is easy and everyone knows the details. But I want to draw a bitmap which is the first frame of the video to the surfaceview.Canvas is not a choice to draw the bitmap, because it will disable the mediaplayer to connect.

Since api level 14, we can new a surface with surfacetexture. So we can use opengl es to draw video frame and bitmap. But I am concerned about the performance.This way of playing video is more complicated and will it cause more overhead? Who can give me some advices?

fadden
  • 51,356
  • 5
  • 116
  • 166
dragonfly
  • 1,151
  • 14
  • 35

1 Answers1

1

You have a few options:

  1. Use a FrameLayout to put a custom View (or maybe just an ImageView) on top of the SurfaceView. Draw your content there. When video playback starts, hide the View.

  2. Connect GLES, draw the first frame, disconnect GLES, connect the MediaPlayer, play the movie. This is essentially what Grafika's PlayMovieSurfaceActivity does to clear the screen to black (see clearSurface()) before playing a movie.

  3. As noted in your question, you can send the video to a SurfaceTexture, and then choose to render your content or render the image from the texture onto the SurfaceView.

#1 is the easiest. #3 adds complexity and is more expensive.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • I think option 2 is the best one. But when I connected the mediaplayer, Can I disconnect it? Because I will connect gles and draw bitmap again later. – dragonfly Sep 29 '15 at 09:15
  • I haven't tried it with MediaPlayer, only MediaCodec. However, releasing the MediaPlayer (or even just telling it to send frames to a different Surface) *should* disconnect it and allow GLES to attach. – fadden Sep 29 '15 at 15:51
  • Option 1 is so easy but it will flash the first frame, I can not find the exact time to make the imageview invisible. Option 3 will cause overhead and consume the battery. Option 2 is the best choice, I will try it later. Thanks! – dragonfly Sep 30 '15 at 01:42
  • I encounter a problem about mediacodec encoding, the encoded video fps is lower than expected but the video file size is much larger than expected. I have update the question here, please see the last section of the question. http://stackoverflow.com/questions/30668846/record-video-with-mediacodec-and-mediamuxer-but-the-bitrate-and-framerate-are-i – dragonfly Oct 01 '15 at 12:37