aws-samples / amazon-ivs-broadcast-android-sample

MIT No Attribution
9 stars 8 forks source link

When I switch between the front and the back camera the view turns to blank until the viewfinder appears #5

Closed qwaskhaled closed 2 years ago

qwaskhaled commented 2 years ago

Is there any way I can freeze the camera when I switch between front and back?

CameraX for Android has an observer that returns the state of the viewFinder which helps at showing the last image of the viewFinder instead of blank

binding.viewFinder.previewStreamState.observe(viewLifecycleOwner, { streamState -> if (streamState == PreviewView.StreamState.STREAMING) {

        }
    })
caleighm commented 2 years ago

Hi @qwaskhaled , here are two ideas for you:

  1. It sounds like you are using the exchangeDevices API and also using the preset front/back cameras. Instead of using the preset cameras, you can manage the camera in your own application so that you can access the CameraX APIs you're interested in. Once your application is managing the camera itself, you can use BroadcastSession.createImageInputSource() to get a SurfaceSource, then call getInputSurface() on that SurfaceSource to get the underlying Surface. Then you can use the Surface to feed data from your application-managed camera to the broadcast session. These APIs can be used for any custom image sources (a camera, static image, etc.)
  2. If you'd like the exchangeDevices API to show the behaviour you're describing, please submit a feature request to IVS so we can add it to our internal roadmap.

Thanks!