Skip to content

Commit

Permalink
Add title and remove suggestion from offlineVideoPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Feb 3, 2024
1 parent 9aa5d0b commit 5be000f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DownloadedCoursesState extends ConsumerState<DownloadedCourses> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
OfflineVideoPlayerPage(localPath: videoDetails.filePath),
OfflineVideoPlayerPage(videoDetails: videoDetails,),
),
);
},
Expand Down
32 changes: 19 additions & 13 deletions lib/views/video_view/offline_video_player/offline_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/models/download/download_state_model.dart';
import 'package:gocast_mobile/models/error/error_model.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/views/chat_view/inactive_view.dart';
import 'package:gocast_mobile/views/video_view/offline_video_player/offline_video_player_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';

class OfflineVideoPlayerPage extends ConsumerStatefulWidget {
final String localPath;
final VideoDetails videoDetails;

const OfflineVideoPlayerPage({
super.key,
required this.localPath,
required this.videoDetails,
});

@override
ConsumerState<OfflineVideoPlayerPage> createState() =>
OfflineVideoPlayerPageState();
}

class OfflineVideoPlayerPageState
extends ConsumerState<OfflineVideoPlayerPage> {
class OfflineVideoPlayerPageState extends ConsumerState<OfflineVideoPlayerPage> {
late OfflineVideoPlayerControllerManager _controllerManager;

Timer? _progressTimer;

Widget _buildVideoLayout() {
return Column(
children: <Widget>[
Expanded(child: _controllerManager.buildVideoPlayer()),
const Expanded(child: InactiveView()),
Expanded(
child: Center( // Center the player
child: AspectRatio(
aspectRatio: _controllerManager.videoPlayerController.value.aspectRatio,
child: _controllerManager.buildVideoPlayer(),
),
),
),
],
);
}


@override
void initState() {
super.initState();
Expand All @@ -56,7 +62,7 @@ class OfflineVideoPlayerPageState
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Replace me with video Title")),
appBar: AppBar(title: Text(widget.videoDetails.name)),
body: ref.read(videoViewModelProvider).isLoading
? const Center(child: CircularProgressIndicator())
: _buildVideoLayout(),
Expand All @@ -71,7 +77,7 @@ class OfflineVideoPlayerPageState
// Initialize the controller manager.
void _initializeControllerManager() {
_controllerManager =
OfflineVideoPlayerControllerManager(localPath: widget.localPath);
OfflineVideoPlayerControllerManager(localPath: widget.videoDetails.filePath);
}

// Initialize the video player and seek to the last progress.
Expand All @@ -89,7 +95,7 @@ class OfflineVideoPlayerPageState
// Seek to the last progress.
Future<void> _seekToLastProgress() async {
final prefs = await SharedPreferences.getInstance();
final progress = prefs.getDouble('progress_${widget.localPath}') ?? 0.0;
final progress = prefs.getDouble('progress_${widget.videoDetails.name}') ?? 0.0;
final position = Duration(
seconds: (progress *
_controllerManager.videoPlayerController.value.duration.inSeconds)
Expand Down Expand Up @@ -140,17 +146,17 @@ class OfflineVideoPlayerPageState

Future<void> _updateProgress(double progress) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setDouble('progress_${widget.localPath}', progress);
await prefs.setDouble('progress_${widget.videoDetails.name}', progress);
}

bool _shouldMarkAsWatched(double progress) {
const watchedThreshold = 0.9; // 90%
const watchedThreshold = 0.8;
return progress >= watchedThreshold;
}

Future<void> _markStreamAsWatched() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('watched_${widget.localPath}', true);
await prefs.setBool('watched_${widget.videoDetails.name}', true);
}

// Simplified loading state management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class OfflineVideoPlayerControllerManager {
cupertinoProgressColors: _getCupertinoProgressColors(),
materialProgressColors: _getMaterialProgressColors(),
placeholder: Container(color: Colors.black),
allowMuting: true,
autoInitialize: true,
allowFullScreen: true,
fullScreenByDefault: false,
showOptions: true,
playbackSpeeds: [0.5,0.75, 1, 1.25, 1.5, 1.75, 2],
);
}

Expand Down

0 comments on commit 5be000f

Please sign in to comment.