图像渲染后MediaPlayer无法渲染到TextureView

编程入门 行业动态 更新时间:2024-10-28 21:25:26
本文介绍了图像渲染后MediaPlayer无法渲染到TextureView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个MediaPlayer将视频呈现到TextureView.工作正常.

I have a MediaPlayer rendering videos to a TextureView. This is working.

现在,我想在此TextureView上显示给定时间的静止图像,然后获取MediaPlayer以便将视频呈现到相同的TextureView.

Now, I want to display a still image on this TextureView for a given time, then get the MediaPlayer to render a video to the same TextureView.

这是渲染位图的代码:

Canvas canvas = mTextureView.lockCanvas(); canvas.drawBitmap(sourceBitmap, matrix, new Paint()); mTextureView.unlockCanvasAndPost(canvas);

此后,任何尝试播放视频的操作都会导致视频播放器触发ERROR_INVALID_OPERATION(-38).

After this, any attempts to play videos result in ERROR_INVALID_OPERATION (-38) being triggered from the video player.

我尝试注释掉对drawBitmap的调用,但该错误仍然发生.看来,先调用lockCanvas然后再调用unlockCanvasAndPost的简单操作会导致TextureView不适合MediaPlayer使用.

I tried commenting out the call to drawBitmap, and the error still happened. It seems that the simple act of calling lockCanvas followed by unlockCanvasAndPost results in the TextureView being unsuitable for the MediaPlayer to use.

是否可以通过某种方式将TextureView重置为允许MediaPlayer使用的状态?

Is there some way that I can reset the TextureView to a state that allows the MediaPlayer to use it?

我正在使用Android 4.2.2.

I'm working on Android 4.2.2.

推荐答案

由于Android应用程序框架的限制(至少从Android 4.4起),您无法执行此操作.

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

TextureView基础的SurfaceTexture是缓冲区使用者. MediaPlayer是缓冲区生产者的一个例子,Canvas是另一个例子.附加生产者后,必须先分离它,然后才能附加第二个生产者.

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.

问题在于无法分离基于软件(画布)的缓冲区生成器.可能有,但没有.因此,一旦使用Canvas进行绘制,便会陷入困境. (此处.)

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.)

您可以分离GLES生产者.例如,在Grafika的视频播放器类之一中,您可以找到 clearSurface()方法,该方法使用GLES将表面清除为黑色.请注意,EGL上下文和窗口是在方法范围内创建并显式释放的.您可以扩展该方法以显示图像.

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.

更多推荐

图像渲染后MediaPlayer无法渲染到TextureView

本文发布于:2023-10-30 01:28:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   MediaPlayer   TextureView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!