How to clear SurfaceTexture after using it with a MediaPlayer?

我是研究僧i 提交于 2019-12-21 03:42:52

问题


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.

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


回答1:


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

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



来源:https://stackoverflow.com/questions/26355512/how-to-clear-surfacetexture-after-using-it-with-a-mediaplayer

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