π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Create new seekbar, duration and time elapsed for new media_kit controls
ashilkn61e1ea4f42f8
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.dartindex 7482be3061..a33e3678a0 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@@ -14,7 +14,9 @@ import "package:photos/models/file/extensions/file_props.dart";import "package:photos/models/file/file.dart";import "package:photos/services/files_service.dart";import "package:photos/theme/colors.dart";+import "package:photos/theme/ente_theme.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";+import "package:photos/utils/debouncer.dart";import "package:photos/utils/dialog_util.dart";import "package:photos/utils/file_util.dart";import "package:photos/utils/toast_util.dart";@@ -23,10 +25,12 @@ class VideoWidgetMediaKitNew extends StatefulWidget {final EnteFile file;final String? tagPrefix;final Function(bool)? playbackCallback;+ final bool isFromMemories;const VideoWidgetMediaKitNew(this.file, {this.tagPrefix,this.playbackCallback,+ this.isFromMemories = false,super.key,});@@ -130,6 +134,27 @@ class _VideoWidgetMediaKitNewState extends State<VideoWidgetMediaKitNew>alignment: Alignment.center,children: [PlayPauseButtonMediaKit(controller),+ Positioned(+ bottom: verticalMargin,+ right: 0,+ left: 0,+ child: SafeArea(+ top: false,+ left: false,+ right: false,+ child: Padding(+ padding: EdgeInsets.only(+ bottom: widget.isFromMemories ? 32 : 0,+ ),+ child: _SeekBarAndDuration(+ controller: controller,+ // showControls: _showControls,+ // isSeeking: _isSeeking,+ ),+ // child: const SizedBox.shrink(),+ ),+ ),+ ),],);},@@ -313,3 +338,344 @@ class _PlayPauseButtonState extends State<PlayPauseButtonMediaKit> {);}}++class _SeekBarAndDuration extends StatelessWidget {+ final VideoController? controller;+ // final ValueNotifier<bool> showControls;+ // final ValueNotifier<bool> isSeeking;++ const _SeekBarAndDuration({+ required this.controller,+ // required this.showControls,+ // required this.isSeeking,+ });++ @override+ Widget build(BuildContext context) {+ return ValueListenableBuilder(+ // valueListenable: showControls,+ valueListenable: ValueNotifier(true),++ builder: (+ BuildContext context,+ bool value,+ _,+ ) {+ return AnimatedOpacity(+ duration: const Duration(+ milliseconds: 200,+ ),+ curve: Curves.easeInQuad,+ opacity: value ? 1 : 0,+ child: IgnorePointer(+ ignoring: !value,+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 8,+ ),+ child: Container(+ padding: const EdgeInsets.fromLTRB(+ 16,+ 4,+ 16,+ 4,+ ),+ decoration: BoxDecoration(+ color: Colors.black.withOpacity(0.3),+ borderRadius: const BorderRadius.all(+ Radius.circular(8),+ ),+ border: Border.all(+ color: strokeFaintDark,+ width: 1,+ ),+ ),+ child: Row(+ children: [+ // AnimatedSize(+ // duration: const Duration(+ // seconds: 5,+ // ),+ // curve: Curves.easeInOut,+ // child: ValueListenableBuilder(+ // valueListenable: controller!.onPlaybackPositionChanged,+ // builder: (+ // BuildContext context,+ // int value,+ // _,+ // ) {+ // return Text(+ // _secondsToDuration(+ // value,+ // ),+ // style: getEnteTextTheme(+ // context,+ // ).mini.copyWith(+ // color: textBaseDark,+ // ),+ // );+ // },+ // ),+ // ),+ StreamBuilder(+ stream: controller?.player.stream.position,+ builder: (context, snapshot) {+ if (snapshot.data == null) {+ return Text(+ "0:00",+ style: getEnteTextTheme(+ context,+ ).mini.copyWith(+ color: textBaseDark,+ ),+ );+ }+ return Text(+ _secondsToDuration(snapshot.data!.inSeconds),+ style: getEnteTextTheme(+ context,+ ).mini.copyWith(+ color: textBaseDark,+ ),+ );+ },+ ),+ Expanded(+ child: _SeekBar(+ controller!,++ // isSeeking,+ ),+ ),+ Text(+ _secondsToDuration(+ controller!.player.state.duration.inSeconds,+ ),+ style: getEnteTextTheme(+ context,+ ).mini.copyWith(+ color: textBaseDark,+ ),+ ),+ ],+ ),+ ),+ ),+ ),+ );+ },+ );+ }++ /// 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')}';+ }+ }++ /// Returns the duration in seconds from the format "h:mm:ss" or "m:ss".+ int? _durationToSeconds(String? duration) {+ if (duration == null) {+ return null;+ }+ final parts = duration.split(':');+ int seconds = 0;++ if (parts.length == 3) {+ // Format: "h:mm:ss"+ seconds += int.parse(parts[0]) * 3600; // Hours to seconds+ seconds += int.parse(parts[1]) * 60; // Minutes to seconds+ seconds += int.parse(parts[2]); // Seconds+ } else if (parts.length == 2) {+ // Format: "m:ss"+ seconds += int.parse(parts[0]) * 60; // Minutes to seconds+ seconds += int.parse(parts[1]); // Seconds+ } else {+ throw FormatException('Invalid duration format: $duration');+ }++ return seconds;+ }+}++class _SeekBar extends StatefulWidget {+ final VideoController controller;+ // final ValueNotifier<bool> isSeeking;+ const _SeekBar(+ this.controller,+ );++ @override+ State<_SeekBar> createState() => _SeekBarState();+}++class _SeekBarState extends State<_SeekBar> {+ final _positionNotifer = ValueNotifier<double>(0.0);+ final _debouncer = Debouncer(+ const Duration(milliseconds: 100),+ executionInterval: const Duration(milliseconds: 325),+ );+ @override+ void initState() {+ super.initState();++ // widget.controller.onPlaybackStatusChanged.addListener(+ // _onPlaybackStatusChanged,+ // );+ // widget.controller.onPlaybackPositionChanged.addListener(+ // _onPlaybackPositionChanged,+ // );++ // _startMovingSeekbar();+ widget.controller.player.stream.position.listen((event) {+ _positionNotifer.value = event.inMilliseconds /+ widget.controller.player.state.duration.inMilliseconds;+ });+ }++ @override+ void dispose() {+ // widget.controller.onPlaybackStatusChanged.removeListener(+ // _onPlaybackStatusChanged,+ // );+ // widget.controller.onPlaybackPositionChanged.removeListener(+ // _onPlaybackPositionChanged,+ // );+ _debouncer.cancelDebounceTimer();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ return SliderTheme(+ data: SliderTheme.of(context).copyWith(+ trackHeight: 1.0,+ thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 8.0),+ overlayShape: const RoundSliderOverlayShape(overlayRadius: 14.0),+ activeTrackColor: colorScheme.primary300,+ inactiveTrackColor: fillMutedDark,+ thumbColor: backgroundElevatedLight,+ overlayColor: fillMutedDark,+ ),+ child: ValueListenableBuilder(+ valueListenable: _positionNotifer,+ builder: (BuildContext context, double value, _) {+ return Slider(+ min: 0.0,+ max: 1.0,+ value: value,+ onChangeStart: (value) {+ // widget.isSeeking.value = true;+ },+ onChanged: (value) {+ // setState(() {+ // _animationController.value = value;+ // });+ // _seekTo(value);+ },+ divisions: 4500,+ onChangeEnd: (value) {+ // setState(() {+ // _animationController.value = value;+ // });+ // _seekTo(value);+ // widget.isSeeking.value = false;+ },+ allowedInteraction: SliderInteraction.tapAndSlide,+ );+ },+ ),+ );+ }++ void _seekTo(double value) {+ _debouncer.run(() async {+ // unawaited(+ // widget.controller.seekTo((value * widget.duration!).round()),+ // );+ });+ }++ // void _startMovingSeekbar() {+ // //Video starts playing after a slight delay. This delay is to ensure that+ // //the seek bar animation starts after the video starts playing.+ // Future.delayed(const Duration(milliseconds: 700), () {+ // if (!mounted) {+ // return;+ // }+ // if (widget.duration != null) {+ // unawaited(+ // _animationController.animateTo(+ // (1 / widget.duration!),+ // duration: const Duration(seconds: 1),+ // ),+ // );+ // } else {+ // unawaited(+ // _animationController.animateTo(+ // 0,+ // duration: const Duration(seconds: 1),+ // ),+ // );+ // }+ // });+ // }++ void _onPlaybackStatusChanged() {+ // if (widget.controller.playbackInfo?.status == PlaybackStatus.paused) {+ // _animationController.stop();+ // }+ }++ void _onPlaybackPositionChanged() async {+ // if (widget.controller.playbackInfo?.status == PlaybackStatus.paused ||+ // (widget.controller.playbackInfo?.status == PlaybackStatus.stopped &&+ // widget.controller.playbackInfo?.positionFraction != 0)) {+ // return;+ // }+ // final target = widget.controller.playbackInfo?.positionFraction ?? 0;++ // //To immediately set the position to 0 when the video ends+ // if (_prevPositionFraction == 1.0 && target == 0.0) {+ // setState(() {+ // _animationController.value = 0;+ // });+ // if (!localSettings.shouldLoopVideo()) {+ // return;+ // }+ // }++ // //There is a slight delay (around 350 ms) for the event being listened to+ // //by this listener on the next target (target that comes after 0). Adding+ // //this buffer to keep the seek bar animation smooth.+ // if (target == 0) {+ // await Future.delayed(const Duration(milliseconds: 450));+ // }++ // if (widget.duration != null) {+ // unawaited(+ // _animationController.animateTo(+ // target + (1 / widget.duration!),+ // duration: const Duration(seconds: 1),+ // ),+ // );+ // } else {+ // unawaited(+ // _animationController.animateTo(+ // target,+ // duration: const Duration(seconds: 1),+ // ),+ // );+ // }++ // _prevPositionFraction = target;+ }+}