Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions test_app/lib/screens/participant_screen/conference_controls.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:dolbyio_comms_sdk_flutter_example/conference_ext.dart';
import 'package:dolbyio_comms_sdk_flutter_example/state_management/models/conference_model.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/bottom_tool_bar.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart';
import 'package:provider/provider.dart';
import '../../widgets/dialogs.dart';
import '../../widgets/spatial_extensions/spatial_values_model.dart';
import '../../widgets/text_form_field.dart';
import '/widgets/conference_action_icon_button.dart';
import 'dart:developer' as developer;

Expand All @@ -27,10 +29,17 @@ class _ConferenceControlsState extends State<ConferenceControls> {
bool isMicOff = false;
bool isVideoOff = false;
bool isScreenShareOff = true;
bool isDialogCanceled = false;
FileConverted? _fileConverted;
TextEditingController urlTextController = TextEditingController();
final formKey = GlobalKey<FormState>();
final testVideoUrl =
'https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';

@override
Widget build(BuildContext context) {
urlTextController.text = testVideoUrl;

return BottomToolBar(children: [
ConferenceActionIconButton(
onPressedIcon: () {
Expand Down Expand Up @@ -81,6 +90,10 @@ class _ConferenceControlsState extends State<ConferenceControls> {
value: 1,
child: Text('Share file'),
),
const PopupMenuItem<int>(
value: 2,
child: Text('Share video'),
),
];
},
onSelected: (value) async {
Expand All @@ -98,6 +111,9 @@ class _ConferenceControlsState extends State<ConferenceControls> {
startFilePresentation();
}
break;
case 2:
startVideoPresentation();
break;
}
},
),
Expand Down Expand Up @@ -154,6 +170,52 @@ class _ConferenceControlsState extends State<ConferenceControls> {
);
}

Future<void> enterUrlDialog(BuildContext context) async {
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return AlertDialog(
title: Column(
children: const [
Text('Enter url'),
Text(
'Should start with https://',
style: TextStyle(color: Colors.black38, fontSize: 12),
),
],
),
content: Form(
key: formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: InputTextFormField(
labelText: 'Url',
controller: urlTextController,
focusColor: Colors.deepPurple,
),
),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
isDialogCanceled = true;
Navigator.pop(context);
},
),
TextButton(
child: const Text('Done'),
onPressed: () {
final isValidForm = formKey.currentState!.validate();
if (isValidForm) {
Navigator.pop(context);
}
},
),
],
);
});
}

Future<void> showResultDialog(
BuildContext context, String title, String text) async {
await ViewDialogs.dialog(
Expand Down Expand Up @@ -275,6 +337,30 @@ class _ConferenceControlsState extends State<ConferenceControls> {
}
}

Future<void> startVideoPresentation() async {
try {
var isSomeonePresentingVideo =
Provider.of<ConferenceModel>(context, listen: false)
.isSomeonePresentingVideo;
if (isSomeonePresentingVideo) {
if (!mounted) return;
showResultDialog(
context, 'Error', 'Someone is already sharing the video');
} else {
await enterUrlDialog(context);
if (!isDialogCanceled) {
_dolbyioCommsSdkFlutterPlugin.videoPresentation
.start(urlTextController.text);
}
}
} catch (error) {
if (!mounted) return;
showResultDialog(context, 'Error', error.toString());
} finally {
isDialogCanceled = false;
}
}

Future<bool> isSomeoneScreenSharing() async {
final conference = await _dolbyioCommsSdkFlutterPlugin.conference.current();
final participants = await _dolbyioCommsSdkFlutterPlugin.conference
Expand Down
96 changes: 96 additions & 0 deletions test_app/lib/screens/participant_screen/participant_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:dolbyio_comms_sdk_flutter_example/state_management/models/conference_model.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/file_presentation_ui.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/spatial_extensions/participant_spatial_values.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/video_presentation_container.dart';
import 'package:provider/provider.dart';
import '../../conference_ext.dart';
import '../../widgets/file_container.dart';
import '../../widgets/spatial_extensions/spatial_values_model.dart';
import '../../widgets/status_snackbar.dart';
import '../../widgets/video_presentation_buttons.dart';
import '../test_buttons/test_buttons.dart';
import 'conference_controls.dart';
import 'conference_title.dart';
Expand All @@ -15,6 +17,7 @@ import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart';
import 'participant_grid.dart';
import '/widgets/dolby_title.dart';
import '/widgets/modal_bottom_sheet.dart';
import 'package:video_player/video_player.dart';

class ParticipantScreen extends StatefulWidget {
final bool isSpatialAudio;
Expand Down Expand Up @@ -83,12 +86,22 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
Event<FilePresentationServiceEventNames, FilePresentation>>?
_onFilePresentationChangeSubscription;

StreamSubscription<Event<VideoPresentationEventNames, VideoPresentation>>?
_onVideoPresentationChangeSubscription;

StreamSubscription<Event<VideoPresentationEventNames, void>>?
_onVideoPresentationStopSubscription;

Participant? _localParticipant;
bool shouldCloseSessionOnLeave = false;
List<ParticipantSpatialValues> participants = [];
bool _isScreenSharing = false;
bool isFilePresenting = false;
bool isLocalPresentingFile = false;
bool isLocalPresentingVideo = false;
bool isVideoStarted = false;
late VideoPlayerController? _videoPlayerController;
late Widget videoPlayerWidget;

@override
void initState() {
Expand Down Expand Up @@ -164,6 +177,51 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
});
}
});

_onVideoPresentationChangeSubscription = _dolbyioCommsSdkFlutterPlugin
.videoPresentation
.onVideoPresentationChange()
.listen((event) async {
if (event.type == VideoPresentationEventNames.videoPresentationStarted) {
String url = event.body.url;
await initializeVideoPlayer(url);
createVideoPlayerWidget();
checkIfLocalPresentingVideo(event);

if (!mounted) return;
Provider.of<ConferenceModel>(context, listen: false)
.isSomeonePresentingVideo = true;
_videoPlayerController?.play();
setState(() => isVideoStarted = true);
} else if (event.type ==
VideoPresentationEventNames.videoPresentationPlayed) {
_videoPlayerController?.play();
} else if (event.type ==
VideoPresentationEventNames.videoPresentationPaused) {
_videoPlayerController?.pause();
} else if (event.type ==
VideoPresentationEventNames.videoPresentationSought) {
_videoPlayerController?.seekTo(Duration.zero);
_videoPlayerController?.play();
}
});

_onVideoPresentationStopSubscription = _dolbyioCommsSdkFlutterPlugin
.videoPresentation
.onVideoPresentationStopped()
.listen((event) {
if (!mounted) {
_onVideoPresentationStopSubscription?.cancel();
} else {
setState(() {
isLocalPresentingVideo = false;
isVideoStarted = false;
Provider.of<ConferenceModel>(context, listen: false)
.isSomeonePresentingVideo = isVideoStarted;
_videoPlayerController?.pause();
});
}
});
}

@override
Expand All @@ -175,6 +233,8 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
_onPermissionsChangeSubsription?.cancel();
_onRecordingChangeSubscription?.cancel();
_onFilePresentationChangeSubscription?.cancel();
_onVideoPresentationChangeSubscription?.cancel();
_onVideoPresentationStopSubscription?.cancel();
super.deactivate();
}

Expand Down Expand Up @@ -212,6 +272,21 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
child: FileContainer(),
)
: const SizedBox.shrink(),
isVideoStarted
? _videoPlayerController != null
? Column(
children: [
VideoPresentationContainer(
videoPlayerController: _videoPlayerController!,
videoPlayerWidget: videoPlayerWidget,
),
isLocalPresentingVideo
? const VideoPresentationButtons()
: const SizedBox.shrink()
],
)
: const SizedBox.shrink()
: const SizedBox.shrink(),
Expanded(
child: Stack(
children: [
Expand All @@ -237,6 +312,27 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
);
}

Future<void> initializeVideoPlayer(String url) async {
_videoPlayerController = VideoPlayerController.network(url);
await Future.wait([
_videoPlayerController!.initialize(),
]);
}

void createVideoPlayerWidget() {
if (_videoPlayerController != null) {
videoPlayerWidget = VideoPlayer(_videoPlayerController!);
}
}

void checkIfLocalPresentingVideo(Event event) async {
var local =
await _dolbyioCommsSdkFlutterPlugin.conference.getLocalParticipant();
if (local.id == event.body.owner.id) {
setState(() => isLocalPresentingVideo = true);
}
}

Future<void> setDefaultSpatialPosition() async {
if (widget.isSpatialAudio) {
final currentConference = await getCurrentConference();
Expand Down
5 changes: 0 additions & 5 deletions test_app/lib/screens/test_buttons/test_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'conference_service_test_buttons.dart';
import 'media_device_service_test_buttons.dart';
import 'notification_service_test_buttons.dart';
import 'recording_service_test_buttons.dart';
import 'video_presentation_service_test_buttons.dart';

class TestButtons extends StatelessWidget {
const TestButtons({Key? key}) : super(key: key);
Expand Down Expand Up @@ -43,10 +42,6 @@ class TestButtons extends StatelessWidget {
SizedBox(height: 10),
CommandServiceTestButtons(),
SizedBox(height: 10),
Text("Video presentation service"),
SizedBox(height: 10),
VideoPresentationServiceTestButtons(),
SizedBox(height: 10),
Text("Notification service"),
SizedBox(height: 10),
NotificationServiceTestButtons(),
Expand Down
Loading