【问题标题】:Textureview get SurfaceTextureview 获取 Surface
【发布时间】:2015-06-22 02:55:04
【问题描述】:

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

Surfaceview 有一个方法:

surfaceView.getHolder().getSurface()

或者TextureView中没有表面?

【问题讨论】:

    标签: android exoplayer


    【解决方案1】:

    第一步是使用getSurfaceTexture()成员函数从TextureView获取SurfaceTexture。

    SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
    

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

    Surface surface = new Surface(surfaceTexture);
    

    有关更多信息,请查看this issue report。它证实了通过按照我描述的方式构造 Surface 对象,可以使用带有 ExoPlayer 的 TextureView 中的 Surface。

    【讨论】:

    • 嘿,谢谢,我是这样处理的,但应用程序仍然会进入异常,还有什么我需要像监听器一样添加的吗?
    • 我没有使用 ExoPlayer 库,但您可能需要实现 TextureView.SurfaceTextureListener 以确保表面有效,然后再尝试访问它。
    【解决方案2】:

    您现在还可以在新版本中将“AnalyticsListener”添加到“SimpleExoPlayer”实例,并实现将表面作为其参数之一的“onRenderedFirstFrame”方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      • 2014-01-09
      • 1970-01-01
      相关资源
      最近更新 更多