3

I'm using a SurfaceTexture which I've created in a ForegroundService to capture videos from the camera without any Activity with SurfaceView.

How can I display my SurfaceTexture in an Activity?

I've been looking for something like SurfaceView.setSurfaceTexture() or a constructor that takes a SurfaceTexture but I couldn't find anything.

Davide Cannizzo
  • 2,434
  • 1
  • 24
  • 31
Sultanen
  • 2,524
  • 5
  • 23
  • 46

1 Answers1

0

I suggest you to create a SurfaceView in the service by calling the constructor like so:

new SurfaceView(getApplicationContext());

So, being the context which the SurfaceView was created with a context common to all your application, you can correctly add your SurfaceView in the content view of the Activity when you need.

Otherwise, you can look at this answer to implement a MediaPlayer that lays out a Surface created by a SurfaceTexture.

Davide Cannizzo
  • 2,434
  • 1
  • 24
  • 31