79638557

Date: 2025-05-26 08:18:12
Score: 0.5
Natty:
Report link

Thanks to @CommonsWare suggestions, using a TextureView instead fixed the issue right away. Here's what I had to change:

In the original layout i was using a SurfaceView, so that got swapped for:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/core_dark100">

    <TextureView
        android:id="@+id/surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center" />

</FrameLayout>

Here I wrapped it in a FrameLayout so that I could control "its" color while the video is still loading. Then in the custom ConstraintLayout implementation for my FPV widget, i replaced the SurfaceView's callbacks with the appropriate one for the TextureView:

binding.surface.isOpaque = false // used to display the FrameLayout's bg color

binding.surface.surfaceTextureListener = object : TextureView.SurfaceTextureListener {
    override fun onSurfaceTextureAvailable(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
        isSurfaceReady = true
        surface = Surface(surfaceTexture)

        surface?.let { doStuff }
    }

    override fun onSurfaceTextureSizeChanged(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
        surface?.let { doStuff }
        isSurfaceReady = true
    }

    override fun onSurfaceTextureDestroyed(surfaceTexture: SurfaceTexture): Boolean {
        isSurfaceReady = false
        surface?.release()
        surface = null
        return true
    }

    override fun onSurfaceTextureUpdated(surfaceTexture: SurfaceTexture) {
        // Called when the SurfaceTexture is updated via updateTexImage()
    }
}

That's all i had to do, now I could pass the surface directly to the DJI API.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @CommonsWare
  • Self-answer (0.5):
Posted by: Stelios Papamichail