Skip to content

Commit

Permalink
[example][screen_sharing] Allow control the preview by user
Browse files Browse the repository at this point in the history
  • Loading branch information
littleGnAl committed Sep 13, 2024
1 parent 62f0323 commit d8c8b45
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions example/lib/examples/advanced/screen_sharing/screen_sharing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ScreenSharing extends StatefulWidget {
class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
late final RtcEngineEx _engine;
bool _isReadyPreview = false;
bool _isStartedPreview = false;
String channelId = config.channelId;
bool isJoined = false;
late TextEditingController _controller;
Expand Down Expand Up @@ -99,7 +100,6 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
_engine.registerEventHandler(_rtcEngineEventHandler);

await _engine.enableVideo();
await _engine.startPreview();
await _engine.setClientRole(role: ClientRoleType.clientRoleBroadcaster);

setState(() {
Expand Down Expand Up @@ -168,7 +168,11 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
Widget build(BuildContext context) {
return ExampleActionsWidget(
displayContentBuilder: (context, isLayoutHorizontal) {
if (!_isReadyPreview) return Container();
if (!_isStartedPreview) {
return const Center(
child: Text('Press the "Start Preview" button to preview'),
);
}
final children = <Widget>[
Expanded(
flex: 1,
Expand Down Expand Up @@ -275,6 +279,35 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
const SizedBox(
height: 20,
),
Row(
children: [
Expanded(
flex: 1,
child: ElevatedButton(
onPressed: () {
if (_isStartedPreview) {
_engine.stopPreview();
_engine.stopPreview(
sourceType: VideoSourceType.videoSourceScreen);
} else {
_engine.startPreview();
_engine.startPreview(
sourceType: VideoSourceType.videoSourceScreen);
}

setState(() {
_isStartedPreview = !_isStartedPreview;
});
},
child:
Text('${_isStartedPreview ? 'Stop' : 'Start'} Preview'),
),
)
],
),
const SizedBox(
height: 20,
),
Row(
children: [
Expanded(
Expand Down Expand Up @@ -384,7 +417,6 @@ class _ScreenShareWebState extends State<ScreenShareWeb>

await rtcEngine.startScreenCapture(
const ScreenCaptureParameters2(captureAudio: true, captureVideo: true));
await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen);
onStartScreenShared();
}

Expand Down Expand Up @@ -457,7 +489,6 @@ class _ScreenShareMobileState extends State<ScreenShareMobile>

await rtcEngine.startScreenCapture(
const ScreenCaptureParameters2(captureAudio: true, captureVideo: true));
await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen);
_showRPSystemBroadcastPickerViewIfNeed();
onStartScreenShared();
}
Expand Down

0 comments on commit d8c8b45

Please sign in to comment.