Created
February 10, 2024 08:34
-
-
Save DhruvamUnikon/fdbd4f4e96ff8d5a2a6f4613d95cf728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await loginRoom(); | |
startListenEvent(); | |
if (widget.isVideo && widget.isHost) { | |
// start recording the screen | |
screenRecordUtils = ZegoScreenRecordUtils(); | |
await screenRecordUtils!.startScreenShare( | |
widget.roomId, | |
widget.user.id, | |
); | |
// ZegoExpressEngine.instance.enableCamera(widget.isVideo); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> startScreenShare(String roomId, String userId) async { | |
// start screen share | |
source ??= (await ZegoExpressEngine.instance.createScreenCaptureSource())!; | |
await ZegoExpressEngine.instance.setVideoConfig( | |
ZegoVideoConfig.preset( | |
ZegoVideoConfigPreset.Preset1080P, | |
), | |
channel: ZegoPublishChannel.Aux, | |
); | |
await ZegoExpressEngine.instance.setVideoSource(ZegoVideoSourceType.ScreenCapture, channel: ZegoPublishChannel.Aux); | |
await ZegoExpressEngine.instance.setAudioSource(ZegoAudioSourceType.Microphone, channel: ZegoPublishChannel.Aux); | |
await source!.startCapture(); | |
String streamID = '${roomId}_${userId}_screen_sharing'; // You can define your stream ID based on your actual business needs. | |
await ZegoExpressEngine.instance.startPublishingStream(streamID, channel: ZegoPublishChannel.Aux); | |
// start recording | |
Directory? tempDir = await getApplicationDocumentsDirectory(); | |
String? tempPath = tempDir.path; | |
try { | |
// Set recording file path, for example, .mp4 format. | |
var filePath = '$tempPath/screen_record.mp4'; | |
// Set recording type | |
var recordType = ZegoDataRecordType.AudioAndVideo; | |
var recordConfig = ZegoDataRecordConfig(filePath, recordType); | |
// Start recording with the main channel. | |
ZegoExpressEngine.instance.startRecordingCapturedData(recordConfig, channel: ZegoPublishChannel.Aux); | |
} catch (e, s) { | |
kDebugMode | |
? debugPrint("Error: An error occurred while starting the recording! $e $s") | |
: null; | |
} | |
} | |
Future<String?> stopScreenShare(String roomId, String userId) async { | |
await source?.stopCapture(); | |
await ZegoExpressEngine.instance.stopPreview(channel: ZegoPublishChannel.Aux); | |
await ZegoExpressEngine.instance.stopPublishingStream(channel: ZegoPublishChannel.Aux); | |
await ZegoExpressEngine.instance.setVideoSource(ZegoVideoSourceType.None, channel: ZegoPublishChannel.Aux); | |
ZegoExpressEngine.instance.stopRecordingCapturedData(channel: ZegoPublishChannel.Aux); | |
await ZegoExpressEngine.instance.setAudioSource(ZegoAudioSourceType.None, channel: ZegoPublishChannel.Aux); | |
if (source != null) { | |
await ZegoExpressEngine.instance.destroyScreenCaptureSource(source!); | |
source = null; | |
} | |
Directory? tempDir = await getApplicationDocumentsDirectory(); | |
String? tempPath = tempDir.path; | |
var filePath = '$tempPath/screen_record.mp4'; | |
return filePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment