TextureView 获取 Surface

Textureview get Surface

我正在使用 ExoPlayer 库,它需要一个 Surface,但是我找不到任何方法来检索 Textureview 的底层 Surface。有什么想法吗?

Surfaceview 有一个方法:

surfaceView.getHolder().getSurface()

或者TextureView中没有surface?

第一步是从 TextureView using the getSurfaceTexture() 成员函数中获取 SurfaceTexture。

SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();

然后从构造函数创建 Surface 对象 Surface(SurfaceTexture surfaceTexture),它将接受来自您的 TextureView 对象的 SurfaceTexture。

Surface surface = new Surface(surfaceTexture);

有关详细信息,请查看 this issue report。它确认通过以我描述的方式构建 Surface 对象,可以将 TextureView 中的 Surface 与 ExoPlayer 一起使用。

您现在还可以在新版本中向 "SimpleExoPlayer" 实例添加一个 "AnalyticsListener",并实现方法 "onRenderedFirstFrame",该方法将曲面作为其参数之一。