Skip to content

armgit / ente

Public Imported from GitHub
0

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

restore the selected speed when the long press is cancelled

aaqild0281824f282
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.dart
index c4368286f8..14717a32a4 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
@@ -46,6 +46,7 @@ class _VideoWidgetState extends State<VideoWidget> {
final _hideControlsDebouncer = Debouncer(const Duration(milliseconds: 2000));
final _isSeekingNotifier = ValueNotifier<bool>(false);
late final StreamSubscription<bool> _isPlayingStreamSubscription;
+ bool _isLongPressSpeedActive = false;
@override
void initState() {
@@ -83,6 +84,18 @@ class _VideoWidgetState extends State<VideoWidget> {
widget.controller.player.setRate(widget.playbackSpeed.value);
}
+ void _startLongPressSpeed() {
+ if (_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = true;
+ widget.controller.player.setRate(kVideoLongPressPlaybackSpeed).ignore();
+ }
+
+ void _restorePlaybackSpeed() {
+ if (!_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = false;
+ widget.controller.player.setRate(widget.playbackSpeed.value).ignore();
+ }
+
void isSeekingListener() {
if (_isSeekingNotifier.value) {
_hideControlsDebouncer.cancelDebounceTimer();
@@ -154,9 +167,7 @@ class _VideoWidgetState extends State<VideoWidget> {
widget.controller.player.pause();
}
} else {
- widget.controller.player
- .setRate(kVideoLongPressPlaybackSpeed)
- .ignore();
+ _startLongPressSpeed();
}
},
onLongPressUp: () {
@@ -169,11 +180,12 @@ class _VideoWidgetState extends State<VideoWidget> {
widget.controller.player.play();
}
} else {
- widget.controller.player
- .setRate(widget.playbackSpeed.value)
- .ignore();
+ _restorePlaybackSpeed();
}
},
+ onLongPressCancel: widget.isFromMemories
+ ? null
+ : _restorePlaybackSpeed,
child: Container(
constraints: const BoxConstraints.expand(),
),
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.dart
index 49b39097f8..59f620caf0 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
@@ -98,6 +98,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
StreamSubscription<DownloadTask>? downloadTaskSubscription;
final _transformationController = TransformationController();
bool _isZooming = false;
+ bool _isLongPressSpeedActive = false;
@override
void initState() {
@@ -301,6 +302,18 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
_controller?.setPlaybackSpeed(widget.playbackSpeed.value);
}
+ void _startLongPressSpeed() {
+ if (_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = true;
+ _controller?.setPlaybackSpeed(kVideoLongPressPlaybackSpeed).ignore();
+ }
+
+ void _restorePlaybackSpeed() {
+ if (!_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = false;
+ _controller?.setPlaybackSpeed(widget.playbackSpeed.value).ignore();
+ }
+
void _onInteractionLockChanged(bool shouldLock) {
if (!mounted) return;
if (_isZooming != shouldLock) {
@@ -399,11 +412,7 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
);
_controller?.pause();
} else {
- _controller
- ?.setPlaybackSpeed(
- kVideoLongPressPlaybackSpeed,
- )
- .ignore();
+ _startLongPressSpeed();
}
},
onLongPressUp: () {
@@ -414,13 +423,12 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
);
_controller?.play();
} else if (!widget.isFromMemories) {
- _controller
- ?.setPlaybackSpeed(
- widget.playbackSpeed.value,
- )
- .ignore();
+ _restorePlaybackSpeed();
}
},
+ onLongPressCancel: widget.isFromMemories
+ ? null
+ : _restorePlaybackSpeed,
child: Container(
constraints: const BoxConstraints.expand(),
),