Update video_viewer.dart

This commit is contained in:
Abinanthankv 2025-01-09 23:27:06 +05:30
parent d416ba644d
commit 1872a0d0d8

View file

@ -21,7 +21,6 @@ import '../types/doc_source.dart';
import 'video_viewer/desktop_video_player.dart';
import 'video_viewer/mobile_video_player.dart';
class VideoViewer extends StatefulWidget {
final DocSource source;
final LibraryItem? meta;
@ -63,6 +62,11 @@ class _VideoViewerState extends State<VideoViewer> {
saveWatchHistory() {
final duration = player.state.duration.inSeconds;
if (duration < 30) {
return;
}
final position = player.state.position.inSeconds;
final progress = duration > 0 ? (position / duration * 100).round() : 0;
@ -187,6 +191,7 @@ class _VideoViewerState extends State<VideoViewer> {
if ((progress ?? []).isEmpty) {
player.play();
return;
}
final duration = Duration(
@ -198,51 +203,12 @@ class _VideoViewerState extends State<VideoViewer> {
player.seek(duration);
player.play();
addListenerForTrakt();
}
List<StreamSubscription> listener = [];
bool traktIntegration = false;
addListenerForTrakt() {
if (traktIntegration == true) {
return;
}
traktIntegration = true;
final streams = player.stream.playing.listen((item) {
if (item) {
TraktService.instance!.startScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
);
} else {
TraktService.instance!.pauseScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
);
}
});
final oneMore = player.stream.completed.listen((item) {
if (item && player.state.duration.inSeconds > 10) {
TraktService.instance!.stopScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
);
}
});
listener.add(streams);
listener.add(oneMore);
}
PlaybackConfig config = getPlaybackConfig();
bool defaultConfigSelected = false;
@override
@ -419,7 +385,7 @@ class _VideoViewerState extends State<VideoViewer> {
_streamListen.cancel();
_duration.cancel();
if (traktIntegration && widget.meta is types.Meta) {
if (widget.meta is types.Meta && player.state.duration.inSeconds > 30) {
TraktService.instance!.stopScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
@ -455,11 +421,9 @@ class _VideoViewerState extends State<VideoViewer> {
setState(() {
isScaled = !isScaled;
});
},
);
String subtitleStyleName = config.subtitleStyle ?? 'Normal';
String subtitleStyleName = config.subtitleStyle ?? 'Normal';
String subtitleStyleColor = config.subtitleColor ?? 'white';
double subtitleSize = config.subtitleSize ;
Color hexToColor(String hexColor) {
@ -480,11 +444,9 @@ class _VideoViewerState extends State<VideoViewer> {
fullscreen: mobile,
normal: mobile,
child: Video(
subtitleViewConfiguration: SubtitleViewConfiguration(
subtitleViewConfiguration: SubtitleViewConfiguration(
style: TextStyle(color: hexToColor(subtitleStyleColor),
// style: TextStyle(color:
fontSize: subtitleSize,
// fontSize: 60.0,
fontStyle: currentFontStyle,
fontWeight: FontWeight.bold),
),
@ -496,9 +458,8 @@ class _VideoViewerState extends State<VideoViewer> {
if (context.mounted) Navigator.of(context).pop();
},
controller: controller,
controls: MaterialVideoControls
controls: MaterialVideoControls,
),
);
}
@ -584,12 +545,10 @@ class _VideoViewerState extends State<VideoViewer> {
languages.containsKey(title)
? languages[title]!
: title,
),
selected:
player.state.track.subtitle.id == currentItem.id,
onTap: () {
player.setSubtitleTrack(currentItem);
Navigator.pop(context);
},
@ -661,4 +620,4 @@ int calculateSecondsFromProgress(
final clampedProgress = progressPercentage.clamp(0.0, 100.0);
final currentSeconds = (duration * (clampedProgress / 100)).round();
return currentSeconds;
}
}