7

I am using the ExoPlayer Library, which expects a Surface, however i couldn't find any Method, which retrieves the underlying Surface of the Textureview. Any Ideas?

The Surfaceview has a method for that:

surfaceView.getHolder().getSurface()

Or is there no surface in TextureView?

user1767754
  • 23,311
  • 18
  • 141
  • 164

2 Answers2

15

First step is to get the SurfaceTexture from the TextureView using the getSurfaceTexture() member function.

SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();

Then create the Surface object from the constructor Surface(SurfaceTexture surfaceTexture) that will accept the SurfaceTexture from your TextureView object.

Surface surface = new Surface(surfaceTexture);

For more information take a look at this issue report. It confirms that by constructing the Surface object in the manner I described it is possible to use the Surface from a TextureView with ExoPlayer.

BrentM
  • 5,671
  • 3
  • 31
  • 38
  • Hey thank you, i had it this way, and still the app steps into an exception, is there anything else i have to add like a listener? – user1767754 Jun 22 '15 at 06:48
  • 2
    I haven't used the ExoPlayer library, but you might need to implement the `TextureView.SurfaceTextureListener` to ensure the surface is valid before you try and access it. – BrentM Jun 22 '15 at 08:08
0

You can also now in the new versions add an "AnalyticsListener" to the "SimpleExoPlayer" instance, and implement the method "onRenderedFirstFrame" which has the surface as one of its parameters.

MarounG
  • 164
  • 3
  • 8