Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix: icons in backup status, make the buttons work, correct bitrate and codec in checking, correctly upload on start

Prateek Sunalbc7400c0a2a8
diff --git a/mobile/assets/2.0x/processing-video-failed.png b/mobile/assets/2.0x/processing-video-failed.png
new file mode 100755
index 0000000000..b6d3888aef
Binary files /dev/null and b/mobile/assets/2.0x/processing-video-failed.png differ
diff --git a/mobile/assets/2.0x/processing-video-success.png b/mobile/assets/2.0x/processing-video-success.png
new file mode 100755
index 0000000000..976d5333b4
Binary files /dev/null and b/mobile/assets/2.0x/processing-video-success.png differ
diff --git a/mobile/assets/2.0x/processing-video.png b/mobile/assets/2.0x/processing-video.png
new file mode 100755
index 0000000000..5c5a92496c
Binary files /dev/null and b/mobile/assets/2.0x/processing-video.png differ
diff --git a/mobile/assets/2.0x/video-processing-queued.png b/mobile/assets/2.0x/video-processing-queued.png
new file mode 100755
index 0000000000..50dd95681c
Binary files /dev/null and b/mobile/assets/2.0x/video-processing-queued.png differ
diff --git a/mobile/assets/3.0x/processing-video-failed.png b/mobile/assets/3.0x/processing-video-failed.png
new file mode 100755
index 0000000000..98b20a830a
Binary files /dev/null and b/mobile/assets/3.0x/processing-video-failed.png differ
diff --git a/mobile/assets/3.0x/processing-video-success.png b/mobile/assets/3.0x/processing-video-success.png
new file mode 100755
index 0000000000..e3984d2bb1
Binary files /dev/null and b/mobile/assets/3.0x/processing-video-success.png differ
diff --git a/mobile/assets/3.0x/processing-video.png b/mobile/assets/3.0x/processing-video.png
new file mode 100755
index 0000000000..c250b5ff1f
Binary files /dev/null and b/mobile/assets/3.0x/processing-video.png differ
diff --git a/mobile/assets/3.0x/video-processing-queued.png b/mobile/assets/3.0x/video-processing-queued.png
new file mode 100755
index 0000000000..193e224590
Binary files /dev/null and b/mobile/assets/3.0x/video-processing-queued.png differ
diff --git a/mobile/assets/processing-video-failed.png b/mobile/assets/processing-video-failed.png
new file mode 100755
index 0000000000..4eaf5c1c45
Binary files /dev/null and b/mobile/assets/processing-video-failed.png differ
diff --git a/mobile/assets/processing-video-success.png b/mobile/assets/processing-video-success.png
new file mode 100755
index 0000000000..aa9dc83f21
Binary files /dev/null and b/mobile/assets/processing-video-success.png differ
diff --git a/mobile/assets/processing-video.png b/mobile/assets/processing-video.png
new file mode 100755
index 0000000000..dcf2c68536
Binary files /dev/null and b/mobile/assets/processing-video.png differ
diff --git a/mobile/assets/video-processing-queued.png b/mobile/assets/video-processing-queued.png
new file mode 100755
index 0000000000..8ee51b1bf8
Binary files /dev/null and b/mobile/assets/video-processing-queued.png differ
diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart
index 8f248d02c6..7133626896 100644
--- a/mobile/lib/models/ffmpeg/ffprobe_props.dart
+++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart
@@ -19,6 +19,7 @@ class FFProbeProps {
String? _width;
String? _height;
int? _rotation;
+ Duration? duration;
// dot separated bitrate, fps, codecWidth, codecHeight. Ignore null value
String get videoInfo {
@@ -134,6 +135,7 @@ class FFProbeProps {
break;
case FFProbeKeys.duration:
parsedData[stringKey] = _formatDuration(json[key]);
+ result.duration = _parseDuration(json[key]);
case FFProbeKeys.location:
result.location = _formatLocation(json[key]);
if (result.location != null) {
diff --git a/mobile/lib/models/preview/preview_item_status.dart b/mobile/lib/models/preview/preview_item_status.dart
index 507dd213ee..8a03c32acc 100644
--- a/mobile/lib/models/preview/preview_item_status.dart
+++ b/mobile/lib/models/preview/preview_item_status.dart
@@ -1,12 +1,12 @@
enum PreviewItemStatus {
- // queued
- inQueue,
- retry,
// in progress
compressing,
uploading,
// error
failed,
+ // queued
+ inQueue,
+ retry,
// done
uploaded,
}
diff --git a/mobile/lib/services/filedata/filedata_service.dart b/mobile/lib/services/filedata/filedata_service.dart
index 96d9668c4f..424bf0210b 100644
--- a/mobile/lib/services/filedata/filedata_service.dart
+++ b/mobile/lib/services/filedata/filedata_service.dart
@@ -23,7 +23,7 @@ class FileDataService {
final _logger = Logger("FileDataService");
final _dio = NetworkClient.instance.enteDio;
late final SharedPreferences _prefs;
- Map<int, PreviewInfo>? previewIds = {};
+ Map<int, PreviewInfo>? previewIds;
void init(SharedPreferences prefs) {
_prefs = prefs;
diff --git a/mobile/lib/services/preview_video_store.dart b/mobile/lib/services/preview_video_store.dart
index 12b29bb7a1..2bf386b724 100644
--- a/mobile/lib/services/preview_video_store.dart
+++ b/mobile/lib/services/preview_video_store.dart
@@ -2,6 +2,7 @@ import "dart:async";
import "dart:collection";
import "dart:io";
+import "package:collection/collection.dart";
import "package:dio/dio.dart";
import "package:encrypt/encrypt.dart" as enc;
import "package:ffmpeg_kit_flutter_full_gpl/ffmpeg_kit.dart";
@@ -116,8 +117,12 @@ class PreviewVideoStore {
if (fileSize <= 10 * 1024 * 1024) {
props = await getVideoPropsAsync(file);
- final codec = props?.propData?["codec"].toString().toLowerCase();
- if (codec == "h264") {
+ final videoData = List.from(props?.propData?["streams"] ?? [])
+ .firstWhereOrNull((e) => e["type"] == "video");
+
+ final codec = videoData["codec_name"]?.toString().toLowerCase();
+ final codecIsH264 = codec?.contains("h264") ?? false;
+ if (codecIsH264) {
return;
}
}
@@ -140,8 +145,13 @@ class PreviewVideoStore {
props ??= await getVideoPropsAsync(file);
- final codec = props?.propData?["codec"]?.toString().toLowerCase();
- final bitrate = int.tryParse(props?.bitrate ?? "");
+ final videoData = List.from(props?.propData?["streams"] ?? [])
+ .firstWhereOrNull((e) => e["type"] == "video");
+
+ final codec = videoData["codec_name"]?.toString().toLowerCase();
+ final bitrate = props?.duration?.inSeconds != null
+ ? (fileSize * 8) / props!.duration!.inSeconds
+ : null;
final String tempDir = Configuration.instance.getTempDirectory();
final String prefix =
@@ -161,7 +171,8 @@ class PreviewVideoStore {
);
FFmpegSession? session;
- if (bitrate != null && bitrate <= 4000 * 1000 && codec == "h264") {
+ final codecIsH264 = codec?.contains("h264") ?? false;
+ if (bitrate != null && bitrate <= 4000 * 1000 && codecIsH264) {
// create playlist without compression, as is
session = await FFmpegKit.execute(
'-i "${file.path}" '
@@ -175,7 +186,7 @@ class PreviewVideoStore {
} else if (bitrate != null &&
codec != null &&
bitrate <= 2000 * 1000 &&
- codec != "h264") {
+ !codecIsH264) {
// compress video with crf=21, h264 no change in resolution or frame rate,
// just change color scheme
session = await FFmpegKit.execute(
@@ -357,7 +368,7 @@ class PreviewVideoStore {
_logger.info("Getting playlist for $file");
try {
final objectKey =
- FileDataService.instance.previewIds![file.uploadedFileID!]?.objectId;
+ FileDataService.instance.previewIds?[file.uploadedFileID!]?.objectId;
final FileInfo? playlistCache = (objectKey == null)
? null
: await cacheManager.getFileFromCache(_getCacheKey(objectKey));
@@ -459,20 +470,41 @@ class PreviewVideoStore {
Future<void> putFilesForPreviewCreation() async {
if (!isVideoStreamingEnabled) return;
- final cutoff = await videoStreamingCutoff;
+ final cutoff = videoStreamingCutoff;
if (cutoff == null) return;
+
final files = await FilesDB.instance.getAllFilesAfterDate(
fileType: FileType.video,
beginDate: cutoff,
);
- final previewIds = FileDataService.instance.previewIds;
- final allFiles = files.where((file) {
- return previewIds?[file.uploadedFileID!] == null;
- }).toList();
+ await Future.delayed(const Duration(seconds: 5));
+ var previewIds = FileDataService.instance.previewIds;
+ if (previewIds == null) {
+ await Future.delayed(const Duration(seconds: 15));
+ previewIds = FileDataService.instance.previewIds;
+ }
+
+ final allFiles = files
+ .where(
+ (file) =>
+ file.uploadedFileID != null &&
+ previewIds?[file.uploadedFileID] == null &&
+ file.fileType == FileType.video,
+ )
+ .toList();
final file = allFiles.first;
allFiles.remove(file);
this.files.addAll(allFiles);
await chunkAndUploadVideo(null, file);
+
+ // set all video status to be in queue
+ for (final file in allFiles) {
+ _items[file.uploadedFileID!] = PreviewItem(
+ status: PreviewItemStatus.inQueue,
+ file: file,
+ collectionID: file.collectionID ?? 0,
+ );
+ }
}
}
diff --git a/mobile/lib/ui/home/status_bar_widget.dart b/mobile/lib/ui/home/status_bar_widget.dart
index 067389e2ee..68302b999d 100644
--- a/mobile/lib/ui/home/status_bar_widget.dart
+++ b/mobile/lib/ui/home/status_bar_widget.dart
@@ -9,6 +9,7 @@ import 'package:photos/events/notification_event.dart';
import "package:photos/events/preview_updated_event.dart";
import 'package:photos/events/sync_status_update_event.dart';
import "package:photos/generated/l10n.dart";
+import "package:photos/models/preview/preview_item_status.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/preview_video_store.dart";
import 'package:photos/services/sync_service.dart';
@@ -34,7 +35,7 @@ class StatusBarWidget extends StatefulWidget {
class _StatusBarWidgetState extends State<StatusBarWidget> {
static final _logger = Logger("StatusBarWidget");
- var previewResult = PreviewVideoStore.instance.previews;
+ int previewCount = 0;
late StreamSubscription<SyncStatusUpdate> _subscription;
late StreamSubscription<NotificationEvent> _notificationSubscription;
@@ -87,9 +88,24 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
}
});
+ // visit LinkedHashMap and calculat previewCount
+ previewCount = PreviewVideoStore.instance.previews.values
+ .where(
+ (element) =>
+ element.status == PreviewItemStatus.compressing ||
+ element.status == PreviewItemStatus.uploading,
+ )
+ .length;
+
_previewSubscription =
Bus.instance.on<PreviewUpdatedEvent>().listen((event) {
- previewResult = event.items;
+ previewCount = event.items.values
+ .where(
+ (element) =>
+ element.status == PreviewItemStatus.compressing ||
+ element.status == PreviewItemStatus.uploading,
+ )
+ .length;
});
super.initState();
}
@@ -119,7 +135,7 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
},
child: const SyncStatusWidget(),
)
- : previewResult.isNotEmpty
+ : previewCount > 0
? GestureDetector(
onTap: () {
routeToPage(
diff --git a/mobile/lib/ui/settings/backup/backup_item_card.dart b/mobile/lib/ui/settings/backup/backup_item_card.dart
index a445c2b7a2..571ecf4e30 100644
--- a/mobile/lib/ui/settings/backup/backup_item_card.dart
+++ b/mobile/lib/ui/settings/backup/backup_item_card.dart
@@ -155,35 +155,40 @@ class _BackupItemCardState extends State<BackupItemCard> {
color: colorScheme.primary700,
),
),
- BackupItemStatus.uploaded => widget.preview != null &&
- widget.preview!.status != PreviewItemStatus.uploaded
+ BackupItemStatus.uploaded => widget.preview != null
? switch (widget.preview!.status) {
- PreviewItemStatus.compressing => const SizedBox(
+ PreviewItemStatus.uploading ||
+ PreviewItemStatus.compressing =>
+ SizedBox(
width: 24,
height: 24,
- child: Text("CQ"),
+ child: Image.asset(
+ "assets/processing-video.png",
+ ),
),
- PreviewItemStatus.uploading => const SizedBox(
- width: 16,
- height: 16,
- child: Text("UQ"),
- ),
- PreviewItemStatus.failed => const SizedBox(
+ PreviewItemStatus.failed => SizedBox(
width: 24,
height: 24,
- child: Text("FQ"),
+ child: Image.asset(
+ "assets/processing-video-failed.png",
+ ),
),
- PreviewItemStatus.inQueue => const SizedBox(
+ PreviewItemStatus.retry ||
+ PreviewItemStatus.inQueue =>
+ SizedBox(
width: 24,
height: 24,
- child: Text("IQ"),
+ child: Image.asset(
+ "assets/video-processing-queued.png",
+ ),
),
- PreviewItemStatus.retry => const SizedBox(
+ PreviewItemStatus.uploaded => SizedBox(
width: 24,
height: 24,
- child: Text("RQ"),
+ child: Image.asset(
+ "assets/processing-video-success.png",
+ ),
),
- _ => const SizedBox()
}
: const SizedBox(
width: 24,
diff --git a/mobile/lib/ui/settings/backup/backup_status_screen.dart b/mobile/lib/ui/settings/backup/backup_status_screen.dart
index ae44bea128..bdd32795c0 100644
--- a/mobile/lib/ui/settings/backup/backup_status_screen.dart
+++ b/mobile/lib/ui/settings/backup/backup_status_screen.dart
@@ -110,8 +110,28 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
);
final allItems = <BackupItem>[
- ...items.where((element) => element.status != BackupItemStatus.uploaded),
- if (result != null) ...result!,
+ ...items.where(
+ (element) => element.status != BackupItemStatus.uploaded,
+ ),
+ if (result != null)
+ ...result!
+ .where(
+ (element) =>
+ element.file.uploadedFileID != null &&
+ previewResult[element.file.uploadedFileID] != null,
+ )
+ .sorted(
+ (a, b) =>
+ previewResult[a.file.uploadedFileID]!.status.index.compareTo(
+ previewResult[b.file.uploadedFileID]!.status.index,
+ ),
+ ),
+ if (result != null)
+ ...result!.where(
+ (element) =>
+ element.file.uploadedFileID == null ||
+ previewResult[element.file.uploadedFileID] == null,
+ ),
];
return Scaffold(
diff --git a/mobile/lib/ui/viewer/file/file_widget.dart b/mobile/lib/ui/viewer/file/file_widget.dart
index 156e322c3c..4926b76b36 100644
--- a/mobile/lib/ui/viewer/file/file_widget.dart
+++ b/mobile/lib/ui/viewer/file/file_widget.dart
@@ -2,9 +2,6 @@ import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
-import "package:photos/services/filedata/filedata_service.dart";
-import "package:photos/services/preview_video_store.dart";
-import "package:photos/ui/viewer/file/preview_video_widget.dart";
import "package:photos/ui/viewer/file/video_widget.dart";
import "package:photos/ui/viewer/file/zoomable_live_image_new.dart";
@@ -43,20 +40,6 @@ class FileWidget extends StatelessWidget {
key: key ?? ValueKey(fileKey),
);
} else if (file.fileType == FileType.video) {
- if (file.isUploaded &&
- file.localID == null &&
- PreviewVideoStore.instance.isVideoStreamingEnabled &&
- (FileDataService.instance.previewIds
- ?.containsKey(file.uploadedFileID!) ??
- false)) {
- return PreviewVideoWidget(
- file,
- tagPrefix: tagPrefix,
- playbackCallback: playbackCallback,
- key: key ?? ValueKey(fileKey),
- );
- }
-
// use old video widget on iOS simulator as the new one crashes while
// playing certain videos on iOS simulator
// if (kDebugMode && Platform.isIOS) {
diff --git a/mobile/lib/ui/viewer/file/preview_status_widget.dart b/mobile/lib/ui/viewer/file/preview_status_widget.dart
index 00cd9f7f8e..c81b5fa199 100644
--- a/mobile/lib/ui/viewer/file/preview_status_widget.dart
+++ b/mobile/lib/ui/viewer/file/preview_status_widget.dart
@@ -15,12 +15,14 @@ class PreviewStatusWidget extends StatefulWidget {
super.key,
required bool showControls,
required this.file,
+ required this.onStreamChange,
this.isPreviewPlayer = false,
}) : _showControls = showControls;
final bool _showControls;
final EnteFile file;
final bool isPreviewPlayer;
+ final void Function()? onStreamChange;
@override
State<PreviewStatusWidget> createState() => _PreviewStatusWidgetState();
@@ -63,13 +65,14 @@ class _PreviewStatusWidgetState extends State<PreviewStatusWidget> {
if (!isVideoStreamingEnabled) {
return const SizedBox();
}
- final bool isPreviewAvailable = FileDataService.instance.previewIds
- ?.containsKey(widget.file.uploadedFileID!) ??
- false;
+ final bool isPreviewAvailable = widget.file.uploadedFileID != null &&
+ (FileDataService.instance.previewIds
+ ?.containsKey(widget.file.uploadedFileID) ??
+ false);
- if (widget.file.localID != null && preview == null) {
- return const SizedBox();
- }
+ // if (widget.file.localID != null && preview == null) {
+ // return const SizedBox();
+ // }
final isInProgress = preview?.status == PreviewItemStatus.compressing ||
preview?.status == PreviewItemStatus.uploading;
final isInQueue = preview?.status == PreviewItemStatus.inQueue ||
@@ -101,70 +104,76 @@ class _PreviewStatusWidgetState extends State<PreviewStatusWidget> {
right: 10,
bottom: 4,
),
- child: Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 8,
- vertical: 4,
- ),
- decoration: BoxDecoration(
- color: isPreviewAvailable ? Colors.green : null,
- borderRadius: const BorderRadius.all(
- Radius.circular(200),
+ child: GestureDetector(
+ onTap:
+ preview == null || preview!.status == PreviewItemStatus.uploaded
+ ? widget.onStreamChange
+ : null,
+ child: Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8,
+ vertical: 4,
),
- border: isPreviewAvailable
- ? null
- : Border.all(
- color: strokeFaintDark,
- width: 1,
- ),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- mainAxisSize: MainAxisSize.min,
- children: [
- !isInProgress
- ? Icon(
- isInQueue
- ? Icons.history_outlined
- : isBeforeCutoffDate
- ? Icons.block_outlined
- : isFailed
- ? Icons.error_outline
- : Icons.play_arrow,
- size: 16,
- )
- : const SizedBox(
- width: 12,
- height: 12,
- child: CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation(
- Colors.white,
+ decoration: BoxDecoration(
+ color: isPreviewAvailable ? Colors.green : null,
+ borderRadius: const BorderRadius.all(
+ Radius.circular(200),
+ ),
+ border: isPreviewAvailable
+ ? null
+ : Border.all(
+ color: strokeFaintDark,
+ width: 1,
+ ),
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ !isInProgress
+ ? Icon(
+ isInQueue
+ ? Icons.history_outlined
+ : isBeforeCutoffDate
+ ? Icons.block_outlined
+ : isFailed
+ ? Icons.error_outline
+ : Icons.play_arrow,
+ size: 16,
+ )
+ : const SizedBox(
+ width: 12,
+ height: 12,
+ child: CircularProgressIndicator(
+ valueColor: AlwaysStoppedAnimation(
+ Colors.white,
+ ),
+ backgroundColor: Colors.transparent,
+ strokeWidth: 2,
),
- backgroundColor: Colors.transparent,
- strokeWidth: 2,
),
- ),
- SizedBox(
- width: !isInProgress || isPreviewAvailable ? 2 : 6,
- ),
- Text(
- isInProgress
- ? "Processing"
- : isInQueue
- ? "Queued"
- : isBeforeCutoffDate
- ? "Ineligible"
- : isFailed
- ? "Failed"
- : widget.isPreviewPlayer
- ? "Play original"
- : "Play stream",
- style: const TextStyle(
- fontSize: 12,
- fontWeight: FontWeight.w600,
+ SizedBox(
+ width: !isInProgress || isPreviewAvailable ? 2 : 6,
),
- ),
- ],
+ Text(
+ isInProgress
+ ? "Processing"
+ : isInQueue
+ ? "Queued"
+ : isBeforeCutoffDate
+ ? "Ineligible"
+ : isFailed
+ ? "Failed"
+ : widget.isPreviewPlayer
+ ? "Play original"
+ : "Play stream",
+ style: const TextStyle(
+ fontSize: 12,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
+ ),
),
),
),
diff --git a/mobile/lib/ui/viewer/file/preview_video_widget.dart b/mobile/lib/ui/viewer/file/preview_video_widget.dart
index 9ad9c35b9b..b275e3d844 100644
--- a/mobile/lib/ui/viewer/file/preview_video_widget.dart
+++ b/mobile/lib/ui/viewer/file/preview_video_widget.dart
@@ -30,12 +30,14 @@ class PreviewVideoWidget extends StatefulWidget {
final bool? autoPlay;
final String? tagPrefix;
final Function(bool)? playbackCallback;
+ final void Function()? onStreamChange;
const PreviewVideoWidget(
this.file, {
this.autoPlay = false,
this.tagPrefix,
this.playbackCallback,
+ this.onStreamChange,
super.key,
});
@@ -91,7 +93,7 @@ class _PreviewVideoWidgetState extends State<PreviewVideoWidget> {
if (file != null) {
if (flagService.internalUser) {
final d =
- FileDataService.instance.previewIds![widget.file.uploadedFileID!];
+ FileDataService.instance.previewIds?[widget.file.uploadedFileID!];
if (d != null && widget.file.fileSize != null) {
// show toast with human readable size
final size = formatBytes(widget.file.fileSize!);
@@ -249,7 +251,10 @@ class _PreviewVideoWidgetState extends State<PreviewVideoWidget> {
looping: true,
allowMuting: true,
allowFullScreen: false,
- customControls: VideoControls(file: widget.file),
+ customControls: VideoControls(
+ file: widget.file,
+ onStreamChange: widget.onStreamChange,
+ ),
);
return Container(
color: Colors.black,
diff --git a/mobile/lib/ui/viewer/file/video_control.dart b/mobile/lib/ui/viewer/file/video_control.dart
index 51c68d08cb..e89e583dd9 100644
--- a/mobile/lib/ui/viewer/file/video_control.dart
+++ b/mobile/lib/ui/viewer/file/video_control.dart
@@ -14,8 +14,10 @@ class VideoControls extends StatefulWidget {
const VideoControls({
super.key,
required this.file,
+ required this.onStreamChange,
});
final EnteFile file;
+ final void Function()? onStreamChange;
@override
State<StatefulWidget> createState() {
@@ -93,6 +95,7 @@ class _VideoControlsState extends State<VideoControls> {
showControls: !_hideStuff,
file: widget.file,
isPreviewPlayer: true,
+ onStreamChange: widget.onStreamChange,
),
_buildBottomBar(context),
],
diff --git a/mobile/lib/ui/viewer/file/video_widget.dart b/mobile/lib/ui/viewer/file/video_widget.dart
index c582cc1e7a..1fa1130379 100644
--- a/mobile/lib/ui/viewer/file/video_widget.dart
+++ b/mobile/lib/ui/viewer/file/video_widget.dart
@@ -5,6 +5,9 @@ import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/use_media_kit_for_video.dart";
import "package:photos/models/file/file.dart";
+import "package:photos/services/filedata/filedata_service.dart";
+import "package:photos/services/preview_video_store.dart";
+import "package:photos/ui/viewer/file/preview_video_widget.dart";
import "package:photos/ui/viewer/file/video_widget_media_kit_new.dart";
import "package:photos/ui/viewer/file/video_widget_native.dart";
@@ -28,6 +31,7 @@ class _VideoWidgetState extends State<VideoWidget> {
bool useNativeVideoPlayer = true;
late final StreamSubscription<UseMediaKitForVideo>
useMediaKitForVideoSubscription;
+ bool selectPreviewForPlay = true;
@override
void initState() {
@@ -49,17 +53,47 @@ class _VideoWidgetState extends State<VideoWidget> {
@override
Widget build(BuildContext context) {
+ final isPreviewVideoPlayable =
+ PreviewVideoStore.instance.isVideoStreamingEnabled &&
+ widget.file.isUploaded &&
+ // widget.file.localID == null &&
+ (FileDataService.instance.previewIds
+ ?.containsKey(widget.file.uploadedFileID!) ??
+ false);
+ if (isPreviewVideoPlayable && selectPreviewForPlay) {
+ return PreviewVideoWidget(
+ widget.file,
+ tagPrefix: widget.tagPrefix,
+ playbackCallback: widget.playbackCallback,
+ onStreamChange: () {
+ setState(() {
+ selectPreviewForPlay = false;
+ });
+ },
+ );
+ }
+
if (useNativeVideoPlayer) {
return VideoWidgetNative(
widget.file,
tagPrefix: widget.tagPrefix,
playbackCallback: widget.playbackCallback,
+ onStreamChange: () {
+ setState(() {
+ selectPreviewForPlay = true;
+ });
+ },
);
} else {
return VideoWidgetMediaKitNew(
widget.file,
tagPrefix: widget.tagPrefix,
playbackCallback: widget.playbackCallback,
+ onStreamChange: () {
+ setState(() {
+ selectPreviewForPlay = true;
+ });
+ },
);
}
}
diff --git a/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart b/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart
index 5bddea1753..7d1ba08cfa 100644
--- a/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart
+++ b/mobile/lib/ui/viewer/file/video_widget_media_kit_new.dart
@@ -27,11 +27,14 @@ class VideoWidgetMediaKitNew extends StatefulWidget {
final String? tagPrefix;
final Function(bool)? playbackCallback;
final bool isFromMemories;
+ final void Function()? onStreamChange;
+
const VideoWidgetMediaKitNew(
this.file, {
this.tagPrefix,
this.playbackCallback,
this.isFromMemories = false,
+ this.onStreamChange,
super.key,
});
@@ -232,11 +235,14 @@ class _VideoWidget extends StatefulWidget {
final VideoController controller;
final Function(bool)? playbackCallback;
final bool isFromMemories;
+ final void Function()? onStreamChange;
+
const _VideoWidget(
this.file,
this.controller,
this.playbackCallback, {
required this.isFromMemories,
+ this.onStreamChange,
});
@override
@@ -368,6 +374,7 @@ class __VideoWidgetState extends State<_VideoWidget> {
return PreviewStatusWidget(
showControls: value,
file: widget.file,
+ onStreamChange: widget.onStreamChange,
);
},
),
diff --git a/mobile/lib/ui/viewer/file/video_widget_native.dart b/mobile/lib/ui/viewer/file/video_widget_native.dart
index e41c99e01d..810bca4dd6 100644
--- a/mobile/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/lib/ui/viewer/file/video_widget_native.dart
@@ -36,11 +36,13 @@ class VideoWidgetNative extends StatefulWidget {
final String? tagPrefix;
final Function(bool)? playbackCallback;
final bool isFromMemories;
+ final void Function()? onStreamChange;
const VideoWidgetNative(
this.file, {
this.tagPrefix,
this.playbackCallback,
this.isFromMemories = false,
+ required this.onStreamChange,
super.key,
});
@@ -283,6 +285,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
return PreviewStatusWidget(
showControls: value,
file: widget.file,
+ onStreamChange: widget.onStreamChange,
);
},
),
diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart
index 1bf215eefb..05bf94a947 100644
--- a/mobile/lib/utils/file_uploader.dart
+++ b/mobile/lib/utils/file_uploader.dart
@@ -475,9 +475,7 @@ class FileUploader {
}
void _uploadPreview(EnteFile file) {
- final collection =
- CollectionsService.instance.getCollectionByID(file.collectionID!);
- if (Platform.isIOS || collection?.displayName == "Camera") {
+ if (file.fileType == FileType.video) {
unawaited(
_previewVideoStore.chunkAndUploadVideo(null, file),
);