π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Show elapsed and total video time
ashilkndf5f9e184b17
diff --git a/mobile/apps/photos/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/native_video_player_controls/seek_bar.dartindex b0fb7e0cc7..f64e7af33f 100644--- a/mobile/apps/photos/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/native_video_player_controls/seek_bar.dart@@ -8,18 +8,28 @@ import "package:photos/events/seekbar_triggered_event.dart";import "package:photos/theme/colors.dart";import "package:photos/ui/viewer/file/video_control/gallery_video_controls.dart";-class SeekBar extends StatefulWidget {+class NativeVideoProgressControls extends StatefulWidget {final NativeVideoPlayerController controller;final int? duration;final ValueNotifier<bool> isSeeking;- const SeekBar(this.controller, this.duration, this.isSeeking, {super.key});++ const NativeVideoProgressControls(+ this.controller,+ this.duration,+ this.isSeeking, {+ super.key,+ });@override- State<SeekBar> createState() => _SeekBarState();+ State<NativeVideoProgressControls> createState() =>+ _NativeVideoProgressControlsState();}-class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {+class _NativeVideoProgressControlsState+ extends State<NativeVideoProgressControls>+ with SingleTickerProviderStateMixin {late final AnimationController _animationController;+ int _elapsedMilliseconds = 0;final _debouncer = Debouncer(const Duration(milliseconds: 100),executionInterval: const Duration(milliseconds: 325),@@ -43,8 +53,8 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {) {if (!mounted || _animationController.value == event.position) return;+ _elapsedMilliseconds = 0;_animationController.value = event.position.toDouble();- setState(() {});});});@@ -67,7 +77,7 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {return AnimatedBuilder(animation: _animationController,builder: (_, _) {- return SliderTheme(+ final seekBar = SliderTheme(data: SliderTheme.of(context).copyWith(trackHeight: 3.0,trackShape: const GalleryVideoSliderTrackShape(),@@ -88,37 +98,36 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {widget.isSeeking.value = true;},onChanged: (value) {- setState(() {- _animationController.value = value;- });+ _elapsedMilliseconds = _positionInMilliseconds(value) ?? 0;+ _animationController.value = value;_seekTo(value);},divisions: 4500,onChangeEnd: (value) {- setState(() {- _animationController.value = value;- });+ _elapsedMilliseconds = _positionInMilliseconds(value) ?? 0;+ _animationController.value = value;_seekTo(value);widget.isSeeking.value = false;},allowedInteraction: SliderInteraction.tapAndSlide,),);+ return GalleryVideoProgressRow(+ seekBar: seekBar,+ elapsedTime: secondsToDuration(_elapsedMilliseconds ~/ 1000),+ totalTime: secondsToDuration(+ (_effectiveDurationInMilliseconds() ?? 0) ~/ 1000,+ ),+ );},);}void _seekTo(double value) {_debouncer.run(() async {- final durationInMilliseconds = _effectiveDurationInMilliseconds();- if (durationInMilliseconds == null) {- return;- }- unawaited(- widget.controller.seekTo(- Duration(milliseconds: (value * durationInMilliseconds).round()),- ),- );+ final position = _positionInMilliseconds(value);+ if (position == null) return;+ unawaited(widget.controller.seekTo(Duration(milliseconds: position)));});}@@ -150,6 +159,7 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {_onPlaybackPositionChanged();break;case PlaybackEndedEvent():+ _elapsedMilliseconds = 0;_animationController.value = 0;default:}@@ -179,6 +189,7 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {return;}+ _elapsedMilliseconds = target;final duration = widget.controller.videoInfo?.durationInMilliseconds;final double fractionTarget = duration == null || duration <= 0? 0@@ -206,6 +217,11 @@ class _SeekBarState extends State<SeekBar> with SingleTickerProviderStateMixin {return null;}+ int? _positionInMilliseconds(double value) {+ final duration = _effectiveDurationInMilliseconds();+ return duration == null ? null : (value * duration).round();+ }+double _durationNudge() {final durationInMilliseconds = _effectiveDurationInMilliseconds();if (durationInMilliseconds == null) {diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart b/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dartindex a10f5a1643..fa6cdff2f8 100644--- a/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/video_control/gallery_video_controls.dart@@ -86,17 +86,23 @@ class GalleryVideoControlScrim extends StatelessWidget {class GalleryVideoProgressRow extends StatelessWidget {final Widget seekBar;- final String duration;+ final String elapsedTime;+ final String totalTime;const GalleryVideoProgressRow({required this.seekBar,- required this.duration,+ required this.elapsedTime,+ required this.totalTime,super.key,});@overrideWidget build(BuildContext context) {final safePadding = MediaQuery.paddingOf(context);+ final timeStyle = getEnteTextTheme(context).tiny.copyWith(+ color: textBaseDark.withValues(alpha: 0.85),+ fontFeatures: const [FontFeature.tabularFigures()],+ );return Padding(padding: EdgeInsets.only(left: safePadding.left + 16,@@ -110,12 +116,7 @@ class GalleryVideoProgressRow extends StatelessWidget {const SizedBox(width: 16),Transform.translate(offset: const Offset(0, -1),- child: Text(- duration,- style: getEnteTextTheme(- context,- ).mini.copyWith(color: textBaseDark.withValues(alpha: 0.85)),- ),+ child: Text('$elapsedTime / $totalTime', style: timeStyle),),const SizedBox(width: 8),const VideoMuteButton(),diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dartindex 6ae35ca257..b1d7ac927c 100644--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart@@ -180,7 +180,7 @@ class _VideoWidgetState extends State<VideoWidget> {top: false,left: false,right: false,- child: SeekBarAndDuration(+ child: _MediaKitVideoProgressControls(controller: widget.controller,isSeekingNotifier: _isSeekingNotifier,),@@ -300,49 +300,24 @@ class _PlayPauseButtonState extends State<PlayPauseButtonMediaKit> {}}-class SeekBarAndDuration extends StatelessWidget {+class _MediaKitVideoProgressControls extends StatefulWidget {final VideoController controller;final ValueNotifier<bool> isSeekingNotifier;- const SeekBarAndDuration({- super.key,+ const _MediaKitVideoProgressControls({required this.controller,required this.isSeekingNotifier,});@override- Widget build(BuildContext context) {- return GalleryVideoProgressRow(- seekBar: SeekBar(controller, isSeekingNotifier),- duration: _secondsToDuration(controller.player.state.duration.inSeconds),- );- }-- /// Returns the duration in the format "h:mm:ss" or "m:ss".- String _secondsToDuration(int totalSeconds) {- final hours = totalSeconds ~/ 3600;- final minutes = (totalSeconds % 3600) ~/ 60;- final seconds = totalSeconds % 60;-- if (hours > 0) {- return '${hours.toString().padLeft(1, '0')}:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';- } else {- return '${minutes.toString().padLeft(1, '0')}:${seconds.toString().padLeft(2, '0')}';- }- }-}--class SeekBar extends StatefulWidget {- final VideoController controller;- final ValueNotifier<bool> isSeekingNotifier;- const SeekBar(this.controller, this.isSeekingNotifier, {super.key});-- @override- State<SeekBar> createState() => _SeekBarState();+ State<_MediaKitVideoProgressControls> createState() =>+ _MediaKitVideoProgressControlsState();}-class _SeekBarState extends State<SeekBar> {+class _MediaKitVideoProgressControlsState+ extends State<_MediaKitVideoProgressControls> {double _sliderValue = 0.0;+ Duration _elapsedTime = Duration.zero;late final StreamSubscription<Duration> _positionStreamSubscription;final _debouncer = Debouncer(const Duration(milliseconds: 300),@@ -356,6 +331,7 @@ class _SeekBarState extends State<SeekBar> {if (widget.isSeekingNotifier.value) return;if (mounted) {setState(() {+ _elapsedTime = event;_sliderValue =(event.inMilliseconds /widget@@ -382,7 +358,7 @@ class _SeekBarState extends State<SeekBar> {@overrideWidget build(BuildContext context) {- return SliderTheme(+ final seekBar = SliderTheme(data: SliderTheme.of(context).copyWith(trackHeight: 3.0,trackShape: const GalleryVideoSliderTrackShape(),@@ -410,40 +386,17 @@ class _SeekBarState extends State<SeekBar> {if (mounted) {setState(() {_sliderValue = value;+ _elapsedTime = _positionAt(value);});}_debouncer.run(() async {- await widget.controller.player.seek(- Duration(- milliseconds:- (value *- widget- .controller- .player- .state- .duration- .inMilliseconds)- .round(),- ),- );+ await widget.controller.player.seek(_positionAt(value));});},divisions: 4500,onChangeEnd: (value) async {- await widget.controller.player.seek(- Duration(- milliseconds:- (value *- widget- .controller- .player- .state- .duration- .inMilliseconds)- .round(),- ),- );+ await widget.controller.player.seek(_positionAt(value));if (mounted) {setState(() {widget.isSeekingNotifier.value = false;@@ -453,5 +406,20 @@ class _SeekBarState extends State<SeekBar> {allowedInteraction: SliderInteraction.tapAndSlide,),);+ return GalleryVideoProgressRow(+ seekBar: seekBar,+ elapsedTime: secondsToDuration(_elapsedTime.inSeconds),+ totalTime: secondsToDuration(+ widget.controller.player.state.duration.inSeconds,+ ),+ );+ }++ Duration _positionAt(double value) {+ return Duration(+ milliseconds:+ (value * widget.controller.player.state.duration.inMilliseconds)+ .round(),+ );}}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 5fde040d39..b9c6e15392 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@@ -425,7 +425,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>left: false,right: false,child: isPlaybackReady- ? _SeekBarAndDuration(+ ? _VideoProgressControls(controller: _controller!,duration: duration,showControls: _showControls,@@ -850,13 +850,13 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>}}-class _SeekBarAndDuration extends StatelessWidget {+class _VideoProgressControls extends StatelessWidget {final NativeVideoPlayerController controller;final String? duration;final ValueNotifier<bool> showControls;final ValueNotifier<bool> isSeeking;- const _SeekBarAndDuration({+ const _VideoProgressControls({required this.controller,required this.duration,required this.showControls,@@ -874,13 +874,10 @@ class _SeekBarAndDuration extends StatelessWidget {opacity: value ? 1 : 0,child: IgnorePointer(ignoring: !value,- child: GalleryVideoProgressRow(- seekBar: SeekBar(- controller,- durationToSeconds(duration),- isSeeking,- ),- duration: duration ?? "0:00",+ child: NativeVideoProgressControls(+ controller,+ durationToSeconds(duration),+ isSeeking,),),);