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

编程入门 行业动态 更新时间:2024-10-28 19:28:58
本文介绍了图像渲染后 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.

这是我渲染位图的代码:

Here's my code to render the bitmap:

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)的缓冲区生产者.可能有,但没有.所以一旦你用 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:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   MediaPlayer   TextureView

发布评论

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

>www.elefans.com

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