Class CameraStreamHandler

  • All Implemented Interfaces:
    MediaSession.StreamHandler

    public class CameraStreamHandler
    extends DefaultStreamHandler
    A managed camera2 MediaSession.StreamHandler using MediaCodec for encoding the Camera stream to h264 frames and uploading to MediaSession.MediaSink. A Typical use case would look like:
       
         session
             .addStream(new MediaSession.CameraStreamBuilder(CHANNEL_NAME,
                 MediaSession.VideoQuality.HD, CameraSelector.DEFAULT_FRONT_CAMERA))
             .observe(this, videoHandler -> {
               if (null == videoHandler) {
                 Log.w(TAG, "onCreate: unable to start the stream");
                 return;
               }
    
               videoHandler.start();
    
               videoHandler.bindToLifecycle(this, this);
    
               binding.cameraDisable.setOnClickListener(v -> videoHandler.stop());
             });
       
     
    • Method Detail

      • bindToLifecycle

        public void bindToLifecycle​(@NonNull
                                    android.content.Context context,
                                    @NonNull
                                    androidx.lifecycle.LifecycleOwner lifecycleOwner,
                                    @Nullable
                                    androidx.camera.view.PreviewView previewView)
        Respects the lifecycle and starts sending the stream data along with preview.
        Parameters:
        context - The context which will be used to bind.
        lifecycleOwner - The lifecycle which everything will bound to.
        previewView - The view which will be used for preview.
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object