Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix seekBar duration for preview videos with missing duration in metadata

Neeraj Guptabd0ad0d1b4c4
diff --git a/mobile/lib/models/preview/playlist_data.dart b/mobile/lib/models/preview/playlist_data.dart
index e5628dc131..6789c1f6d3 100644
--- a/mobile/lib/models/preview/playlist_data.dart
+++ b/mobile/lib/models/preview/playlist_data.dart
@@ -7,12 +7,14 @@ class PlaylistData {
int? width;
int? height;
int? size;
+ int? durationInSeconds;
PlaylistData({
required this.preview,
this.width,
this.height,
this.size,
+ this.durationInSeconds,
});
PlaylistData copyWith({
@@ -20,12 +22,14 @@ class PlaylistData {
int? width,
int? height,
int? size,
+ int? durationInSeconds,
}) {
return PlaylistData(
preview: preview ?? this.preview,
width: width ?? this.width,
height: height ?? this.height,
size: size ?? this.size,
+ durationInSeconds: durationInSeconds ?? this.durationInSeconds,
);
}
@@ -35,6 +39,7 @@ class PlaylistData {
'width': width,
'height': height,
'size': size,
+ 'durationInSeconds': durationInSeconds,
};
}
@@ -42,7 +47,7 @@ class PlaylistData {
@override
String toString() {
- return 'PlaylistData(preview: $preview, width: $width, height: $height, size: $size)';
+ return 'PlaylistData(preview: $preview, width: $width, height: $height, size: $size, durationInSeconds: $durationInSeconds)';
}
@override
diff --git a/mobile/lib/services/preview_video_store.dart b/mobile/lib/services/preview_video_store.dart
index c734bf56d9..732050197c 100644
--- a/mobile/lib/services/preview_video_store.dart
+++ b/mobile/lib/services/preview_video_store.dart
@@ -636,6 +636,7 @@ class PreviewVideoStore {
width: width,
height: height,
size: size,
+ durationInSeconds: parseDurationFromHLS(finalPlaylist),
);
if (shouldAppendPreview) {
FileDataService.instance.appendPreview(
@@ -650,6 +651,17 @@ class PreviewVideoStore {
}
}
+ int? parseDurationFromHLS(String playlist) {
+ final lines = playlist.split("\n");
+ for (final line in lines) {
+ if (line.startsWith("#EXT-X-TARGETDURATION")) {
+ final duration = line.split(":").last.trim();
+ return int.tryParse(duration);
+ }
+ }
+ return null;
+ }
+
Future<(String, String)> _getPreviewUrl(EnteFile file) async {
try {
final response = await _dio.get(
diff --git a/mobile/lib/ui/viewer/file/video_widget_native.dart b/mobile/lib/ui/viewer/file/video_widget_native.dart
index 15ad2e1bb2..68653265c7 100644
--- a/mobile/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/lib/ui/viewer/file/video_widget_native.dart
@@ -646,9 +646,14 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
if (widget.playlistData != null && widget.selectedPreview) {
aspectRatio = widget.playlistData!.width! / widget.playlistData!.height!;
- if (widget.file.duration != null &&
- (duration == "0:00" || duration == null)) {
- duration = secondsToDuration(widget.file.duration!);
+ if (duration == "0:00" || duration == null) {
+ if ((widget.file.duration ?? 0) > 0) {
+ duration = secondsToDuration(widget.file.duration!);
+ } else if (widget.playlistData!.durationInSeconds != null) {
+ duration = secondsToDuration(
+ widget.playlistData!.durationInSeconds!,
+ );
+ }
}
_logger.info("Getting aspect ratio from preview video");
return;