MediaSourceManager class
Creates and manages media sources for camera capture and video playback.
Signature:
export declare class MediaSourceManager extends ExternalObject
Extends: ExternalObject
Methods
Method | Modifiers | Description |
---|---|---|
createCameraSource(config) | Creates a media source that captures the video feed of a camera on the device and outputs it. | |
createVideoPlayerSource(config) | Creates a media source that outputs the playback of a video file. | |
lockCameras() | Locks the configuration of all camera media sources. | |
unlockCameras() | Unlocks all camera media sources, applying any changes made while they were locked. |
MediaSourceManager.createCameraSource() method
Creates a media source that captures the video feed of a camera on the device and outputs it.
Signature:
createCameraSource(config?: CameraMediaSourceConfig): Promise<CameraMediaSource>;
Parameters
Parameter | Type | Description |
---|---|---|
config | CameraMediaSourceConfig | (Optional) The configuration for creating the camera media source, if not specified default values are used for all options. |
Returns:
Promise<CameraMediaSource>
A promise that resolves with the created CameraMediaSource instance.
Remarks
When a new camera media source is created the camera capture will be disabled initially for that source. Call CameraMediaSource.startCamera() to start capturing the camera.
MediaSourceManager.createVideoPlayerSource() method
Creates a media source that outputs the playback of a video file.
Signature:
createVideoPlayerSource(config?: VideoPlayerMediaSourceConfig): Promise<VideoPlayerMediaSource>;
Parameters
Parameter | Type | Description |
---|---|---|
config | VideoPlayerMediaSourceConfig | (Optional) The configuration for creating the video player media source, if not specified default values are used for all options. |
Returns:
Promise<VideoPlayerMediaSource>
A promise that resolves with the created VideoPlayerMediaSource instance. If a video URL was specified in the configuration, the promise will resolve when the video is ready to play.
Remarks
When a new video player media source is created with a video URL specified in the configuration, the video will be paused initially. Call VideoPlayerMediaSource.play() to start playing.
MediaSourceManager.lockCameras() method
Locks the configuration of all camera media sources.
Signature:
lockCameras(): Promise<void>;
Returns:
Promise<void>
A promise that resolves when all camera media sources are in a locked state.
Remarks
This allows you to change the states of multiple camera media sources by calling methods such as CameraMediaSource.startCamera(), CameraMediaSource.stopCamera(), CameraMediaSource.setCameraType() and CameraMediaSource.requestResolutionScale() and then apply all those changes at once when MediaSourceManager.unlockCameras() is called. This avoids unnecessary intermediate state changes which could impact performance.
If this method is called multiple times, you must call MediaSourceManager.unlockCameras() an equal number of times to unlock.
Example
// Note: This only works on devices that support dual camera
const frontCamera = await mediaSourceManager.createCameraSource();
const backCamera = await mediaSourceManager.createCameraSource();
// Lock
await mediaSourceManager.lockCameras();
// Set camera positions and start
frontCamera.setCameraType(CameraType.FrontFacing);
backCamera.setCameraType(CameraType.RearFacing);
const frontCameraStarted = frontCamera.startCamera();
const backCameraStarted = backCamera.startCamera();
// Unlock and wait for cameras to start
mediaSourceManager.unlockCameras();
await Promise.all([frontCameraStarted, backCameraStarted]);
MediaSourceManager.unlockCameras() method
Unlocks all camera media sources, applying any changes made while they were locked.
Signature:
unlockCameras(): void;
Returns:
void
Updated 7 months ago