Skip to content

Commit

Permalink
GIve an option for different camera views (#243)
Browse files Browse the repository at this point in the history
* Added different camera views download options

* Cleaned code in custom_video_control_bar.dart and added error message as saidd

---------

Co-authored-by: ge59dil <[email protected]>
  • Loading branch information
Anishyou and ge59dil authored Jan 25, 2024
1 parent 438b484 commit 02950ca
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
42 changes: 40 additions & 2 deletions lib/views/video_view/utils/custom_video_control_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: <Widget>[
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);
Expand Down Expand Up @@ -77,7 +115,7 @@ class CustomVideoControlBar extends StatelessWidget {
.read(userViewModelProvider.notifier)
.pinCourse(currentStream.courseID);
} else if (choice == 'Download') {
onDownload();
_showDownloadOptions(context);
}
},
itemBuilder: (BuildContext context) {
Expand Down
16 changes: 8 additions & 8 deletions lib/views/video_view/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VideoPlayerPageState extends ConsumerState<VideoPlayerPage> {
currentStream: widget.stream,
isChatVisible: _isChatVisible,
isChatActive: _isChatActive,
onDownload: () => _downloadVideo(widget.stream),
onDownload: (type) => _downloadVideo(widget.stream,type),
),
Expanded(
child:
Expand Down Expand Up @@ -236,20 +236,20 @@ class VideoPlayerPageState extends ConsumerState<VideoPlayerPage> {
});
}

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;
}
Expand All @@ -262,7 +262,7 @@ class VideoPlayerPageState extends ConsumerState<VideoPlayerPage> {
// 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')),
Expand Down

0 comments on commit 02950ca

Please sign in to comment.