Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Added different camera views download options
Browse files Browse the repository at this point in the history
  • Loading branch information
ge59dil committed Jan 25, 2024
1 parent 438b484 commit 50c5d95
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
41 changes: 39 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 @@ -24,6 +24,43 @@ class CustomVideoControlBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
void showDownloadOptions() {
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');
},
),
],
),
);
},
);
}

List<Map<String, IconData>> getMenuItems(bool isPinned, bool isDownloaded) {
List<Map<String, IconData>> items = [
Expand Down Expand Up @@ -77,7 +114,7 @@ class CustomVideoControlBar extends StatelessWidget {
.read(userViewModelProvider.notifier)
.pinCourse(currentStream.courseID);
} else if (choice == 'Download') {
onDownload();
showDownloadOptions();
}
},
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')),
const SnackBar(content: Text('Downloads not allowed 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 50c5d95

Please sign in to comment.