Class ScreenCapturer

java.lang.Object
com.twilio.video.ScreenCapturer
All Implemented Interfaces:
VideoCapturer, VideoCapturer

public class ScreenCapturer extends Object implements VideoCapturer
The ScreenCapturer class is used to provide video frames for a LocalVideoTrack from a device's screen. The frames are provided via the MediaProjection api. This capturer is only compatible with Build.VERSION_CODES.LOLLIPOP or higher.

This class represents an implementation of a VideoCapturer interface. Although public, these methods are not meant to be invoked directly.

Note: This capturer can be reused, but cannot be shared across multiple LocalVideoTracks simultaneously.

  • Constructor Details

    • ScreenCapturer

      public ScreenCapturer(@NonNull android.content.Context context, int screenCaptureIntentResult, @NonNull android.content.Intent screenCaptureIntentData, @Nullable ScreenCapturer.Listener screenCapturerListener, int framesPerSecond)
    • ScreenCapturer

      public ScreenCapturer(@NonNull android.content.Context context, int screenCaptureIntentResult, @NonNull android.content.Intent screenCaptureIntentData, @Nullable ScreenCapturer.Listener screenCapturerListener)
  • Method Details

    • getCaptureFormat

      public VideoFormat getCaptureFormat()
      Specified by:
      getCaptureFormat in interface VideoCapturer
    • isScreencast

      public boolean isScreencast()
      Indicates that the screen capturer is a screencast.
      Specified by:
      isScreencast in interface VideoCapturer
      Returns:
      true if-and-only-if this is a screen capturer.
    • initialize

      public void initialize(@NonNull SurfaceTextureHelper surfaceTextureHelper, @NonNull android.content.Context context, @NonNull CapturerObserver capturerObserver)
      Description copied from interface: VideoCapturer
      This function is used to initialize the camera thread, the android application context, and the capture observer. It will be called only once and before any startCapture() request. The camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants to deliver texture frames, it should do this by rendering on the SurfaceTexture in surfaceTextureHelper, register itself as a listener, and forward the frames to CapturerObserver.onFrameCaptured(). The caller still has ownership of surfaceTextureHelper and is responsible for making sure surfaceTextureHelper.dispose() is called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new VideoCapturer once the previous VideoCapturer has been disposed.
      Specified by:
      initialize in interface VideoCapturer
    • startCapture

      public void startCapture(int width, int height, int framerate)
      Description copied from interface: VideoCapturer
      Start capturing frames in a format that is as close as possible to width x height and framerate.
      Specified by:
      startCapture in interface VideoCapturer
    • stopCapture

      public void stopCapture()
      Stops all frames being captured. MediaProjection should be available for use upon completion.

      Note: This method is not meant to be invoked directly.

      Specified by:
      stopCapture in interface VideoCapturer
    • dispose

      public void dispose()
      Description copied from interface: VideoCapturer
      This method provides an optional step to perform a final cleanup.
      Specified by:
      dispose in interface VideoCapturer
      Specified by:
      dispose in interface VideoCapturer