MediaPlayer cannot render to TextureView after image render

你离开我真会死。 提交于 2019-11-28 10:28:58

You can't do this, due to a limitation of the Android app framework (as of Android 4.4 at least).

The SurfaceTexture that underlies the TextureView is a buffer consumer. The MediaPlayer is one example of a buffer producer, Canvas is another. Once you attach a producer, you have to detach it before you can attach a second producer.

The trouble is that there is no way to detach a software-based (Canvas) buffer producer. There could be, but isn't. So once you draw with Canvas, you're stuck. (There's a note to that effect here.)

You can detach a GLES producer. For example, in one of Grafika's video player classes you can find a clearSurface() method that clears the surface to black using GLES. Note the EGL context and window are created and explicitly released within the scope of the method. You could expand the method to show an image instead.

I have encountered similar problems recently. My intention was to show video thumbnail directly into TextureView and then use the same TextureView to play video, without using another ImageView to display video thumbnail.

I implemented the second approach in @fadden's comments, use EGL to draw video thumbnail into the same TextureView.

In addition, we can also use two textures in GLSurfaceView to achieve the same goal. One external OES texture to play continuous video, and another 2D texture to display video thumbnail.

The full demo can be found in this github project EGLPoster.

Hopefully it will be helpful for anyone reaches here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!