与MediaPlayer结合使用后如何清除SurfaceTexture? [英] How to clear SurfaceTexture after using it with a MediaPlayer?

查看:1643
本文介绍了与MediaPlayer结合使用后如何清除SurfaceTexture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有TextureView子级的ListView. TextureView使用MediaPlayer播放视频.回收TextureView后,最后一帧仍保留在表面上,直到下一个MediaPlayer对其使用为止.

I'm using a ListView with TextureView children. The TextureView uses a MediaPlayer to play videos. When the TextureView gets recycled, the last frame remains on the surface until the next MediaPlayer makes use of it.

最简单的方法是清除" TextureView的表面(例如黑色),以免出现旧框架?

What is the easiest way to "clear" the TextureView's surface (e.g black) so the old frames do not appear?

推荐答案

经过一段时间的努力,我提出了两种可能的解决方案:

After struggling with this for a while, I've come up with a couple of possible solutions:

a)使用GLES清洁表面.您可以在 Grafika 中查看示例(签出clearSurface()方法).我个人不喜欢这种方式,因为我认为向黑色过渡不是特别好,而且如果您还没有使用GL代码,那么这会占用相当多的技术开销.此外,这似乎仅适用于API 17 +.

a) clear the surface using GLES. You can see an example in Grafika (check out the clearSurface() method). I'm personally not a fan of this because I don't think that a jarring transition to black looks particularly good, and it's a fair bit of technical overhead if you aren't already using GL code. Additionally, this only seems to work for API 17+.

b)我选择的解决方案是简单地创建一个新的TextureView,并在每次我想播放视频时将其添加到适当的视图中,而不是重用旧的视频.我会毫不犹豫地称其为"<好> "解决方案,但这是我所能找到的最不可怕的解决方案.

b) My chosen solution was to simply create a new TextureView and add it to the appropriate view every time I wanted to play a video, instead of reusing an old one. I would hesitate to call this a good solution, but it's the least horrible one I could find.

c)如果您再次播放同一视频,您可能可以做的一件事就是尝试在视频播放完后搜索到视频的第一帧.然后下一次最后一帧闪烁时,由于它与视频的开头是同一帧,因此将不可见.我在此方面取得了一些成功,但无法使其在所有设备上都能可靠地工作.显然,这也是黑客.

c) One thing you might be able to do if you're playing the same video again is to try to seek to the first frame of the video when it's done playing. Then the next time the last frame flashes, it won't be visible since it will be the same frame as the beginning of the video. I had some success with this but couldn't get it to work reliably on all devices. It's also pretty clearly a hack.

祝你好运,这让尝试解决问题感到非常沮丧.

Good luck, this was immensely frustrating to try to fix.

这篇关于与MediaPlayer结合使用后如何清除SurfaceTexture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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