class DefaultScreenCaptureSource : VideoCaptureSource, VideoSink
DefaultScreenCaptureSource uses MediaProjection to create a VirtualDisplay to capture the device screen. It will render the captured frames to a Surface provided by a SurfaceTextureCaptureSourceFactory.
Builders will need to get permission from users to obtain the activityResultCode and activityData arguments, required to create an internal MediaProjection object. Read content share guide for more information.
Note that you must finish starting the foreground service before calling start. Otherwise start will fail to succeed despite having the user grant permission and despite having created a foreground service for the MediaProjection. CaptureSourceObserver.onCaptureFailed will be called with CaptureSourceError.SystemFailure in this case.
If the MediaProjection could not be obtained with the activityResultCode and activityData, CaptureSourceObserver.onCaptureFailed will be called with CaptureSourceError.ConfigurationFailure.
<init> |
DefaultScreenCaptureSource uses MediaProjection to create a VirtualDisplay to capture the device screen. It will render the captured frames to a Surface provided by a SurfaceTextureCaptureSourceFactory. DefaultScreenCaptureSource(context: Context, logger: Logger, surfaceTextureCaptureSourceFactory: SurfaceTextureCaptureSourceFactory, activityResultCode: Int, activityData: Intent, displayManager: DisplayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager, mediaProjectionManager: MediaProjectionManager = context.getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager) |
contentHint |
Content hint for downstream processing val contentHint: VideoContentHint |
addCaptureSourceObserver |
Add a capture source observer to receive callbacks from the source on lifecycle events which can be used to trigger UI. This observer is entirely optional. fun addCaptureSourceObserver(observer: CaptureSourceObserver): Unit |
addVideoSink |
Add a video sink which will immediately begin to receive new frames. fun addVideoSink(sink: VideoSink): Unit |
onVideoFrameReceived |
Receive a video frame from some upstream source. The VideoSink may render, store, process, and forward the frame, among other applications. fun onVideoFrameReceived(frame: VideoFrame): Unit |
release |
fun release(): Unit |
removeCaptureSourceObserver |
Remove a capture source observer fun removeCaptureSourceObserver(observer: CaptureSourceObserver): Unit |
removeVideoSink |
Remove a video sink which will no longer receive new frames on return fun removeVideoSink(sink: VideoSink): Unit |
setMaxResolution |
Set max resolution for video capture source DefaultCameraCaptureSource and DefaultScreenCaptureSource call this function to set max resolution for camera and screen capture fun setMaxResolution(maxResolution: VideoResolution): Unit |
start |
Start capturing on this source and emitting video frames fun start(): Unit |
stop |
Stop capturing on this source and cease emitting video frames fun stop(): Unit |