From 02950cabed27190ac46d0ea81ea2a9c8a38863ba Mon Sep 17 00:00:00 2001 From: Anishyou <123313052+Anishyou@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:15:51 +0100 Subject: [PATCH] GIve an option for different camera views (#243) * Added different camera views download options * Cleaned code in custom_video_control_bar.dart and added error message as saidd --------- Co-authored-by: ge59dil --- .../utils/custom_video_control_bar.dart | 42 ++++++++++++++++++- lib/views/video_view/video_player.dart | 16 +++---- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/lib/views/video_view/utils/custom_video_control_bar.dart b/lib/views/video_view/utils/custom_video_control_bar.dart index e406f995..9a3f1250 100644 --- a/lib/views/video_view/utils/custom_video_control_bar.dart +++ b/lib/views/video_view/utils/custom_video_control_bar.dart @@ -5,7 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; class CustomVideoControlBar extends StatelessWidget { final VoidCallback onToggleChat; - final VoidCallback onDownload; + final Function(String) onDownload; final VoidCallback onOpenQuizzes; final Stream currentStream; final bool isChatVisible; @@ -21,6 +21,44 @@ class CustomVideoControlBar extends StatelessWidget { required this.onDownload, }); + void _showDownloadOptions(BuildContext context) { + showModalBottomSheet( + context: context, + builder: (BuildContext context) { + return SafeArea( + child: Wrap( + children: [ + ListTile( + leading: const Icon(Icons.download), + title: const Text('Combined'), + onTap: () { + Navigator.pop(context); + onDownload('Combined'); + }, + ), + ListTile( + leading: const Icon(Icons.present_to_all), + title: const Text('Presentation Only'), + onTap: () { + Navigator.pop(context); + onDownload('Presentation'); + }, + ), + ListTile( + leading: const Icon(Icons.videocam), + title: const Text('Camera'), + onTap: () { + Navigator.pop(context); + onDownload('Camera Only'); + }, + ), + ], + ), + ); + }, + ); + } + @override Widget build(BuildContext context) { ThemeData themeData = Theme.of(context); @@ -77,7 +115,7 @@ class CustomVideoControlBar extends StatelessWidget { .read(userViewModelProvider.notifier) .pinCourse(currentStream.courseID); } else if (choice == 'Download') { - onDownload(); + _showDownloadOptions(context); } }, itemBuilder: (BuildContext context) { diff --git a/lib/views/video_view/video_player.dart b/lib/views/video_view/video_player.dart index fe184a3c..57d3ce9b 100644 --- a/lib/views/video_view/video_player.dart +++ b/lib/views/video_view/video_player.dart @@ -41,7 +41,7 @@ class VideoPlayerPageState extends ConsumerState { currentStream: widget.stream, isChatVisible: _isChatVisible, isChatActive: _isChatActive, - onDownload: () => _downloadVideo(widget.stream), + onDownload: (type) => _downloadVideo(widget.stream,type), ), Expanded( child: @@ -236,20 +236,20 @@ class VideoPlayerPageState extends ConsumerState { }); } - void _downloadVideo(Stream stream) { + void _downloadVideo(Stream stream,String type) { // Extract the "Combined" download URL from the Stream object - String? combinedDownloadUrl; + String? downloadUrl; for (var download in stream.downloads) { - if (download.friendlyName == "Combined") { - combinedDownloadUrl = download.downloadURL; + if (download.friendlyName == type) { + downloadUrl = download.downloadURL; break; } } //combinedDownloadUrl="https://file-examples.com/storage/fe5048eb7365a64ba96daa9/2017/04/file_example_MP4_480_1_5MG.mp4"; // Check if the Combined URL is found - if (combinedDownloadUrl == null) { + if (downloadUrl == null) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Combined download URL not found')), + SnackBar(content: Text('Download type "$type" not available for this lecture')), ); return; } @@ -262,7 +262,7 @@ class VideoPlayerPageState extends ConsumerState { // Call the download function from the StreamViewModel ref .read(downloadViewModelProvider.notifier) - .downloadVideo(combinedDownloadUrl, stream.id, fileName) + .downloadVideo(downloadUrl, stream.id, fileName) .then((localPath) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Video Downloaded')),