图像渲染后MediaPlayer无法渲染到TextureView [英] MediaPlayer cannot render to TextureView after image render

查看:168
本文介绍了图像渲染后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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆