π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve iOS native video metadata and dismiss handling
Neeraj Guptad23689a5c456
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dartindex 1c195b15f8..5f2e1cd126 100644--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart@@ -36,6 +36,7 @@ import "package:photos/ui/viewer/file/zoomable_video_viewer.dart";import "package:photos/utils/dialog_util.dart";import "package:photos/utils/exif_util.dart";import "package:photos/utils/file_util.dart";+import "package:video_player/video_player.dart" as vp;import "package:visibility_detector/visibility_detector.dart";class VideoWidgetNative extends StatefulWidget {@@ -224,6 +225,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>@overridevoid dispose() {_subscription?.cancel();+ _controller?.stop().ignore();_controller?.dispose();if (downloadTaskSubscription != null) {downloadTaskSubscription!.cancel();@@ -295,6 +297,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>: (d) => {if (d.delta.dy > dragSensitivity){+ _stopPlaybackBeforeDismiss(),Navigator.of(context).pop(),}else if (d.delta.dy < (dragSensitivity * -1))@@ -455,6 +458,15 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>);}+ void _stopPlaybackBeforeDismiss() {+ _controller?.pause();+ _controller?.stop().ignore();+ widget.playbackCallback?.call(+ false,+ FullScreenRequestReason.userInteraction,+ );+ }+Future<void> _initializeController(NativeVideoPlayerController controller,) async {@@ -750,6 +762,21 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>_logger.info("Getting aspect ratio from preview video");return;}+ if (Platform.isIOS) {+ // FFprobe in ffmpeg_kit can crash on certain iOS media files.+ // On iOS, use lightweight metadata probing via AVPlayer.+ if (widget.file.hasDimensions) {+ aspectRatio = widget.file.width / widget.file.height;+ } else {+ aspectRatio ??= 1;+ }+ if ((duration == null || duration == "0:00") &&+ (widget.file.duration ?? 0) > 0) {+ duration = secondsToDuration(widget.file.duration!);+ }+ await _setAspectAndDurationFromIosPlayerProbe();+ return;+ }final videoProps = await getVideoPropsAsync(File(_filePath!));if (videoProps != null) {duration = videoProps.propData?["duration"];@@ -770,6 +797,48 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>aspectRatio = 1;}}++ Future<void> _setAspectAndDurationFromIosPlayerProbe() async {+ final path = _filePath;+ if (path == null) return;+ vp.VideoPlayerController? metadataController;+ try {+ metadataController = vp.VideoPlayerController.file(File(path));+ await metadataController.initialize().timeout(const Duration(seconds: 4));+ final value = metadataController.value;+ final probeAspectRatio = value.aspectRatio;+ if ((aspectRatio == null || aspectRatio == 1) && probeAspectRatio > 0) {+ aspectRatio = probeAspectRatio;+ }+ final durationInMilliseconds = value.duration.inMilliseconds;+ if ((duration == null || duration == "0:00") &&+ durationInMilliseconds > 0) {+ duration = secondsToDuration(durationInMilliseconds ~/ 1000);+ }+ } on TimeoutException catch (e, s) {+ _logger.warning(+ "_setAspectAndDurationFromIosPlayerProbe timed out for ${widget.file.generatedID}",+ e,+ s,+ );+ } catch (e, s) {+ _logger.warning(+ "_setAspectAndDurationFromIosPlayerProbe failed for ${widget.file.generatedID}",+ e,+ s,+ );+ } finally {+ try {+ await metadataController?.dispose();+ } catch (e, s) {+ _logger.warning(+ "_setAspectAndDurationFromIosPlayerProbe dispose failed for ${widget.file.generatedID}",+ e,+ s,+ );+ }+ }+ }}class _SeekBarAndDuration extends StatelessWidget {