createScreenShareVideoTrack static method
Creates a screen-share track before sharing. Pass the result to Room.enableScreenShare.
encoderConfigpicks a screen-share profile; the SDK sets the capture size, bitrate and frame rate that go with it.multiStreampublishes the profile as several quality layers (simulcast) instead of one.withAudioalso captures system audio into the microphone track, so muting the mic silences both. No separate share-audio stream is created, and nothing is sent while the mic is off. Android 10+ only — on iOS the broadcast extension decides. Apps that block playback capture (Chrome, for example) are captured as silence.
No capture starts here. On Android this asks the user for screen-capture
consent; on iOS the system picker opens later, from
Room.enableScreenShare. Returns null when the user declines, and
throws a VideoSDKError (3071) for a profile the SDK does not know.
Example
final track = await VideoSDK.createScreenShareVideoTrack(
encoderConfig: CustomScreenShareTrackConfig.h720p_15fps,
);
if (track != null) await room.enableScreenShare(customTrack: track);
Implementation
static Future<CustomStreamTrack?> createScreenShareVideoTrack({
CustomScreenShareTrackConfig encoderConfig =
CustomScreenShareTrackConfig.h720p_15fps,
bool multiStream = false,
bool withAudio = false,
}) async {
final handle = await _channel.invokeMethod<Map<dynamic, dynamic>>(
'track.createScreenShareVideo',
{
'encoderConfig': encoderConfig.name,
'multiStream': multiStream,
'withAudio': withAudio,
},
);
// Null is the declined-consent answer, not a failure: the native factory
// reports a bad profile name as an error instead.
if (handle == null) return null;
final trackId = handle['trackId'] as String? ?? '';
return CustomStreamTrack.shareTrack(
mediaStream: NativeMediaStream(
id: trackId,
ownerTag: 'local',
tracks: [MediaStreamTrack(id: trackId, kind: 'video')],
),
shareEncoderConfig: encoderConfig,
multiStream: multiStream,
withAudio: withAudio,
);
}