Skip to content

armgit / ente

Public Imported from GitHub
0

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

Match external video controls to the gallery player

ashil-pilot178e7458e9c2
diff --git a/mobile/apps/photos/integration_test/external_video_viewer_test.dart b/mobile/apps/photos/integration_test/external_video_viewer_test.dart
index b00b4e2abc..ce4ff56fe6 100644
--- a/mobile/apps/photos/integration_test/external_video_viewer_test.dart
+++ b/mobile/apps/photos/integration_test/external_video_viewer_test.dart
@@ -3,6 +3,7 @@ import "dart:convert";
import "dart:io";
import "dart:typed_data";
+import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
import "package:integration_test/integration_test.dart";
@@ -11,6 +12,9 @@ import "package:path_provider/path_provider.dart";
import "package:photo_manager/photo_manager.dart";
import "package:photos/ui/viewer/file/external_video_viewer.dart";
import "package:photos/ui/viewer/file/native_video_player_controls/play_pause_button.dart";
+import "package:photos/ui/viewer/file/video_control/gallery_video_controls.dart";
+import "package:photos/ui/viewer/file/video_control/mute_button.dart";
+import "package:photos/ui/viewer/file/viewer_app_bar.dart";
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@@ -42,9 +46,14 @@ void main() {
tester,
() => controller.playbackStatus == PlaybackStatus.paused,
);
- await tester.tap(find.byIcon(Icons.volume_up));
+ await tester.tap(find.byType(VideoMuteIconButton));
await _pumpUntil(tester, () => controller.volume == 0);
- expect(find.byIcon(Icons.volume_off), findsOneWidget);
+ expect(
+ tester
+ .widget<VideoMuteIconButton>(find.byType(VideoMuteIconButton))
+ .isMuted,
+ isTrue,
+ );
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
await tester.runAsync(
@@ -100,21 +109,24 @@ void main() {
tester,
() =>
state.isFullscreen &&
- find.byType(AppBar).evaluate().isEmpty &&
+ find.byIcon(Icons.fullscreen_exit).evaluate().isNotEmpty &&
(Platform.isIOS ||
MediaQuery.orientationOf(
tester.element(find.byType(ExternalVideoViewer)),
) ==
Orientation.landscape),
);
- expect(find.byType(AppBar), findsNothing);
+ expect(
+ tester.widget<AppBar>(find.byType(AppBar)).backgroundColor,
+ Colors.transparent,
+ );
expect(state.controller, same(controller));
await tester.binding.handlePopRoute();
await _pumpUntil(
tester,
() =>
!state.isFullscreen &&
- find.byType(AppBar).evaluate().isNotEmpty &&
+ find.byIcon(Icons.fullscreen).evaluate().isNotEmpty &&
(Platform.isIOS ||
MediaQuery.orientationOf(
tester.element(find.byType(ExternalVideoViewer)),
@@ -130,12 +142,105 @@ void main() {
(_) {},
onDone: closed.complete,
);
- await tester.pumpWidget(const SizedBox.shrink());
+ await _showControls(tester);
+ await tester.tap(find.byIcon(Icons.arrow_back));
await _pumpUntil(tester, () => closed.isCompleted);
+ expect(find.text("Viewer closed"), findsOneWidget);
await subscription.cancel();
expect(tester.takeException(), isNull);
});
+ testWidgets("gallery gestures, speed selection, and coordinated controls", (
+ tester,
+ ) async {
+ final state = await _openVideo(tester, videoFile.path);
+ final controller = state.controller!;
+ await _showControls(tester);
+ await tester.tap(find.byType(PlayPauseButton));
+ await _pumpUntil(
+ tester,
+ () => controller.playbackStatus == PlaybackStatus.paused,
+ );
+
+ await _doubleTapVideo(tester, forward: true);
+ await _pumpUntil(
+ tester,
+ () => controller.playbackPosition >= const Duration(milliseconds: 3500),
+ );
+ await _doubleTapVideo(tester, forward: false);
+ await _pumpUntil(
+ tester,
+ () => controller.playbackPosition <= const Duration(milliseconds: 200),
+ );
+ expect(controller.playbackStatus, PlaybackStatus.paused);
+ expect(find.text("5s"), findsOneWidget);
+
+ final moreTooltip = MaterialLocalizations.of(
+ tester.element(find.byType(ExternalVideoViewer)),
+ ).moreButtonTooltip;
+ await tester.tap(find.byTooltip(moreTooltip));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text("Playback speed"));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text("1.5x"));
+ await tester.pumpAndSettle();
+ await _pumpUntil(tester, () => controller.playbackSpeed == 1.5);
+ expect(controller.playbackStatus, PlaybackStatus.paused);
+ await tester.tap(find.byType(PlayPauseButton));
+ await _pumpUntil(
+ tester,
+ () => controller.playbackStatus == PlaybackStatus.playing,
+ );
+
+ final gesturePoint = _videoGesturePoint(tester, forward: false);
+ var hold = await tester.startGesture(gesturePoint);
+ await tester.pump(const Duration(milliseconds: 600));
+ await _pumpUntil(tester, () => controller.playbackSpeed == 2);
+ expect(find.byType(VideoLongPressSpeedIndicator), findsOneWidget);
+ await hold.up();
+ await _pumpUntil(tester, () => controller.playbackSpeed == 1.5);
+ expect(find.byType(VideoLongPressSpeedIndicator), findsNothing);
+
+ hold = await tester.startGesture(gesturePoint);
+ await tester.pump(const Duration(milliseconds: 600));
+ await _pumpUntil(tester, () => controller.playbackSpeed == 2);
+ await hold.cancel();
+ await _pumpUntil(tester, () => controller.playbackSpeed == 1.5);
+ expect(find.byType(VideoLongPressSpeedIndicator), findsNothing);
+
+ hold = await tester.startGesture(gesturePoint);
+ await tester.pump(const Duration(milliseconds: 600));
+ await _pumpUntil(tester, () => controller.playbackSpeed == 2);
+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
+ await _pumpUntil(
+ tester,
+ () =>
+ controller.playbackStatus == PlaybackStatus.paused &&
+ controller.playbackSpeed == 1.5,
+ );
+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
+ await hold.cancel();
+ await _pumpUntil(
+ tester,
+ () => controller.playbackStatus == PlaybackStatus.playing,
+ );
+ expect(find.byType(VideoLongPressSpeedIndicator), findsNothing);
+ expect(controller.playbackSpeed, 1.5);
+
+ await _pumpUntil(tester, () => !_appBar(tester).visible);
+ final controlsOpacity = tester.widget<AnimatedOpacity>(
+ find.ancestor(
+ of: find.byType(PlayPauseButton),
+ matching: find.byType(AnimatedOpacity),
+ ),
+ );
+ expect(controlsOpacity.opacity, 0);
+ await _showControls(tester);
+ expect(_appBar(tester).visible, isTrue);
+ await tester.pumpWidget(const SizedBox.shrink());
+ expect(tester.takeException(), isNull);
+ });
+
testWidgets("plays an Android content URI without a filesystem path", (
tester,
) async {
@@ -197,7 +302,7 @@ void main() {
tester,
) async {
await tester.pumpWidget(
- MaterialApp(home: _TestViewer(uri: "${videoFile.path}.missing")),
+ _testApp(_TestViewer(uri: "${videoFile.path}.missing")),
);
await _pumpUntil(
tester,
@@ -221,6 +326,7 @@ class _TestViewer extends StatefulWidget {
class _TestViewerState extends State<_TestViewer> {
final _videoKey = GlobalKey<ExternalVideoViewerState>();
bool _fullscreen = false;
+ bool _closed = false;
@override
Widget build(BuildContext context) {
@@ -232,13 +338,15 @@ class _TestViewerState extends State<_TestViewer> {
}
},
child: Scaffold(
- appBar: _fullscreen ? null : AppBar(),
- body: ExternalVideoViewer(
- key: _videoKey,
- uri: widget.uri,
- onFullscreenChanged: (fullscreen) =>
- setState(() => _fullscreen = fullscreen),
- ),
+ body: _closed
+ ? const Center(child: Text("Viewer closed"))
+ : ExternalVideoViewer(
+ key: _videoKey,
+ uri: widget.uri,
+ onBackPressed: () => setState(() => _closed = true),
+ onFullscreenChanged: (fullscreen) =>
+ setState(() => _fullscreen = fullscreen),
+ ),
),
);
}
@@ -248,12 +356,7 @@ Future<ExternalVideoViewerState> _openVideo(
WidgetTester tester,
String uri,
) async {
- await tester.pumpWidget(
- MaterialApp(
- key: ValueKey(uri),
- home: _TestViewer(uri: uri),
- ),
- );
+ await tester.pumpWidget(_testApp(_TestViewer(uri: uri), key: ValueKey(uri)));
final state = tester.state<ExternalVideoViewerState>(
find.byType(ExternalVideoViewer),
);
@@ -267,18 +370,41 @@ Future<ExternalVideoViewerState> _openVideo(
return state;
}
-Future<void> _showControls(WidgetTester tester) async {
- final opacity = tester.widget<AnimatedOpacity>(
- find.descendant(
- of: find.byType(ExternalVideoViewer),
- matching: find.byType(AnimatedOpacity),
- ),
+Widget _testApp(Widget home, {Key? key}) => MaterialApp(
+ key: key,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ locale: const Locale("en"),
+ home: home,
+);
+
+ViewerAppBar _appBar(WidgetTester tester) =>
+ tester.widget<ViewerAppBar>(find.byType(ViewerAppBar));
+
+Offset _videoGesturePoint(WidgetTester tester, {required bool forward}) {
+ final bounds = tester.getRect(find.byType(ExternalVideoViewer));
+ return Offset(
+ bounds.left + bounds.width * (forward ? 0.8 : 0.2),
+ bounds.center.dy,
);
- if (opacity.opacity == 0) {
- final bounds = tester.getRect(find.byType(ExternalVideoViewer));
- await tester.tapAt(bounds.topLeft + const Offset(20, 20));
+}
+
+Future<void> _doubleTapVideo(
+ WidgetTester tester, {
+ required bool forward,
+}) async {
+ final point = _videoGesturePoint(tester, forward: forward);
+ await tester.tapAt(point);
+ await tester.pump(const Duration(milliseconds: 100));
+ await tester.tapAt(point);
+ await tester.pump(const Duration(milliseconds: 100));
+}
+
+Future<void> _showControls(WidgetTester tester) async {
+ if (!_appBar(tester).visible) {
+ await tester.tapAt(_videoGesturePoint(tester, forward: false));
}
- await tester.pump(const Duration(milliseconds: 250));
+ await tester.pump(const Duration(milliseconds: 350));
}
Future<void> _pumpUntil(WidgetTester tester, bool Function() condition) async {
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
index c567a66bee..5ac4b6645f 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
@@ -419,6 +419,7 @@ class FileViewerState extends State<FileViewer> {
return ExternalVideoViewer(
uri: uri,
key: _externalVideoKey,
+ onBackPressed: () => unawaited(_closeViewer()),
onFullscreenChanged: (fullscreen) {
setState(() => _isVideoFullscreen = fullscreen);
},
@@ -426,8 +427,12 @@ class FileViewerState extends State<FileViewer> {
}
Widget _buildSingleFileScaffold() {
+ final isVideo =
+ action.type == MediaType.video ||
+ widget.sharedMediaFile?.type == SharedMediaType.video;
+ final uri = widget.sharedMediaFile?.path ?? action.data;
return Scaffold(
- appBar: _isVideoFullscreen
+ appBar: isVideo && uri != null && uri.isNotEmpty
? null
: AppBar(
leading: IconButton(
diff --git a/mobile/apps/photos/lib/ui/viewer/file/external_video_viewer.dart b/mobile/apps/photos/lib/ui/viewer/file/external_video_viewer.dart
index 04bf49ed50..1034a50f5f 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/external_video_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/external_video_viewer.dart
@@ -1,22 +1,33 @@
import "dart:async";
import "dart:io";
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.dart";
import "package:native_video_player/native_video_player.dart";
import "package:photos/ui/viewer/file/native_video_player_controls/play_pause_button.dart";
+import "package:photos/ui/viewer/file/native_video_player_controls/seek_bar.dart";
+import "package:photos/ui/viewer/file/video_control/gallery_video_controls.dart";
+import "package:photos/ui/viewer/file/video_control/mute_button.dart";
+import "package:photos/ui/viewer/file/video_control/video_speed_bottom_sheet.dart";
+import "package:photos/ui/viewer/file/video_double_tap_seek.dart";
import "package:photos/ui/viewer/file/video_seek_controller.dart";
+import "package:photos/ui/viewer/file/viewer_app_bar.dart";
import "package:video_player/video_player.dart" as vp;
import "package:wakelock_plus/wakelock_plus.dart";
class ExternalVideoViewer extends StatefulWidget {
final String uri;
final ValueChanged<bool> onFullscreenChanged;
+ final VoidCallback onBackPressed;
const ExternalVideoViewer({
required this.uri,
required this.onFullscreenChanged,
+ required this.onBackPressed,
super.key,
});
@@ -31,6 +42,7 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
StreamSubscription<PlaybackEvent>? _subscription;
late final VideoSeekController _seekController;
Timer? _hideControlsTimer;
+ OverlayEntry? _longPressSpeedIndicator;
bool _hasError = false;
bool _isPlaybackReady = false;
bool _preparingPlayback = false;
@@ -39,6 +51,8 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
bool _resumePlayback = false;
bool _showControls = true;
bool _isSeeking = false;
+ bool _isShowingMenu = false;
+ double _playbackSpeed = 1;
double? _displayAspectRatio;
NativeVideoPlayerController? get controller => _controller;
@@ -192,6 +206,7 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
_logger.warning("Could not play external video", error, stackTrace);
if (!mounted || _hasError) return;
_hideControlsTimer?.cancel();
+ _removeLongPressSpeedIndicator();
unawaited(_subscription?.cancel());
_controller?.dispose();
_controller = null;
@@ -209,6 +224,7 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
!_isPlaybackReady ||
_controller?.playbackStatus == PlaybackStatus.playing;
_isForeground = false;
+ _stopLongPressSpeed();
unawaited(_run(() async => _controller?.pause()));
unawaited(WakelockPlus.disable());
} else if (state == AppLifecycleState.resumed) {
@@ -224,16 +240,21 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
if (!mounted) return;
final isSeeking = _seekController.state.isInteracting;
if (_isSeeking != isSeeking) {
- _isSeeking = isSeeking;
- if (isSeeking) _showControls = true;
+ setState(() {
+ _isSeeking = isSeeking;
+ if (isSeeking) _showControls = true;
+ });
_scheduleHideControls();
}
- setState(() {});
}
void _scheduleHideControls() {
_hideControlsTimer?.cancel();
- if (_controller?.playbackStatus == PlaybackStatus.playing && !_isSeeking) {
+ if (_isForeground &&
+ _controller?.playbackStatus == PlaybackStatus.playing &&
+ !_isSeeking &&
+ !_isShowingMenu &&
+ _longPressSpeedIndicator == null) {
_hideControlsTimer = Timer(const Duration(seconds: 2), () {
if (mounted) setState(() => _showControls = false);
});
@@ -260,6 +281,7 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_hideControlsTimer?.cancel();
+ _removeLongPressSpeedIndicator();
unawaited(_subscription?.cancel());
_controller?.dispose();
_seekController.dispose();
@@ -273,14 +295,83 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
super.dispose();
}
- @override
- Widget build(BuildContext context) {
- if (_hasError) {
- return const ColoredBox(
- color: Colors.black,
- child: Center(child: Icon(Icons.error_outline, color: Colors.white)),
+ void _startLongPressSpeed() {
+ if (!_isForeground ||
+ _controller?.playbackStatus != PlaybackStatus.playing ||
+ _longPressSpeedIndicator != null) {
+ return;
+ }
+ _longPressSpeedIndicator = showVideoLongPressSpeedIndicator(context);
+ _hideControlsTimer?.cancel();
+ unawaited(
+ _run(() => _controller!.setPlaybackSpeed(kVideoLongPressPlaybackSpeed)),
+ );
+ }
+
+ void _stopLongPressSpeed() {
+ if (_longPressSpeedIndicator == null) return;
+ _removeLongPressSpeedIndicator();
+ unawaited(_run(() async => _controller?.setPlaybackSpeed(_playbackSpeed)));
+ _scheduleHideControls();
+ }
+
+ void _removeLongPressSpeedIndicator() {
+ _longPressSpeedIndicator?.remove();
+ _longPressSpeedIndicator?.dispose();
+ _longPressSpeedIndicator = null;
+ }
+
+ void _toggleControls() {
+ setState(() => _showControls = !_showControls);
+ _scheduleHideControls();
+ }
+
+ void _onBackPressed() {
+ if (_isFullscreen) {
+ unawaited(exitFullscreen());
+ } else {
+ widget.onBackPressed();
+ }
+ }
+
+ Future<void> _showPlaybackMenu(BuildContext buttonContext) async {
+ _isShowingMenu = true;
+ _hideControlsTimer?.cancel();
+ try {
+ final selected = await showEntePopupMenu<bool>(
+ context: buttonContext,
+ options: [
+ EntePopupMenuOption(
+ value: true,
+ label: context.strings.playbackSpeed,
+ leadingWidget: const HugeIcon(
+ icon: HugeIcons.strokeRoundedDashboardSpeed02,
+ size: IconSizes.small,
+ ),
+ trailingWidget: Text(
+ _playbackSpeed == 1 ? "1x" : "${_playbackSpeed}x",
+ style: TextStyles.tiny,
+ ),
+ ),
+ ],
+ );
+ if (!mounted || _hasError || selected != true) return;
+ await showVideoSpeedBottomSheet(
+ context,
+ currentSpeed: _playbackSpeed,
+ onSpeedSelected: (speed) {
+ setState(() => _playbackSpeed = speed);
+ unawaited(_run(() => _controller!.setPlaybackSpeed(speed)));
+ },
);
+ } finally {
+ _isShowingMenu = false;
+ if (mounted) _scheduleHideControls();
}
+ }
+
+ @override
+ Widget build(BuildContext context) {
final info = _controller?.videoInfo;
final aspectRatio =
_displayAspectRatio ??
@@ -292,117 +383,125 @@ class ExternalVideoViewerState extends State<ExternalVideoViewer>
child: Stack(
fit: StackFit.expand,
children: [
- Center(
- child: AspectRatio(
- aspectRatio: aspectRatio,
- child: NativeVideoPlayerView(onViewReady: _initializeController),
+ if (_hasError)
+ const Center(child: Icon(Icons.error_outline, color: Colors.white))
+ else ...[
+ Center(
+ child: AspectRatio(
+ aspectRatio: aspectRatio,
+ child: NativeVideoPlayerView(
+ onViewReady: _initializeController,
+ ),
+ ),
+ ),
+ if (!_isPlaybackReady)
+ const Center(
+ child: CircularProgressIndicator(color: Colors.white),
+ ),
+ if (_isPlaybackReady) ..._buildControls(),
+ ],
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ height: MediaQuery.paddingOf(context).top + 80,
+ child: ViewerAppBar(
+ visible: _hasError || _showControls,
+ onBackPressed: _onBackPressed,
+ actions: _isPlaybackReady && !_hasError
+ ? [
+ IconButton(
+ onPressed: () =>
+ unawaited(_setFullscreen(!_isFullscreen)),
+ icon: Icon(
+ _isFullscreen
+ ? Icons.fullscreen_exit
+ : Icons.fullscreen,
+ ),
+ ),
+ Builder(
+ builder: (buttonContext) => IconButton(
+ tooltip: MaterialLocalizations.of(
+ context,
+ ).moreButtonTooltip,
+ onPressed: () =>
+ unawaited(_showPlaybackMenu(buttonContext)),
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedMoreVertical,
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ]
+ : [],
),
),
- if (!_isPlaybackReady)
- const Center(child: CircularProgressIndicator(color: Colors.white)),
- if (_isPlaybackReady) _buildControls(),
],
),
);
}
- Widget _buildControls() {
- final duration = _seekController.duration ?? Duration.zero;
- final position = _seekController.position;
- final isMuted = _controller!.volume == 0;
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- setState(() => _showControls = !_showControls);
- _scheduleHideControls();
- },
- child: AnimatedOpacity(
+ List<Widget> _buildControls() {
+ final controller = _controller!;
+ final isMuted = controller.volume == 0;
+ return [
+ AnimatedOpacity(
opacity: _showControls ? 1 : 0,
duration: const Duration(milliseconds: 200),
- child: IgnorePointer(
- ignoring: !_showControls,
- child: Stack(
- children: [
- Center(child: PlayPauseButton(_controller)),
- Positioned(
- left: 0,
- right: 0,
- bottom: 0,
- child: SafeArea(
- top: false,
- child: ColoredBox(
- color: Colors.black54,
- child: Row(
- children: [
- Expanded(
- child: Slider(
- value: duration > Duration.zero
- ? (position.inMilliseconds /
- duration.inMilliseconds)
- .clamp(0.0, 1.0)
- : 0,
- activeColor: Colors.white,
- inactiveColor: Colors.white30,
- onChangeStart: _seekController.canSeek
- ? (_) =>
- _seekController.beginSliderInteraction()
- : null,
- onChanged: _seekController.canSeek
- ? (value) => _seekController.updateSliderTarget(
- _positionAt(value),
- )
- : null,
- onChangeEnd: _seekController.canSeek
- ? (value) => _seekController
- .endSliderInteraction(_positionAt(value))
- : null,
- ),
- ),
- Text(
- "${_formatTime(position)} / ${_formatTime(duration)}",
- style: const TextStyle(
- color: Colors.white,
- fontSize: 12,
- ),
- ),
- IconButton(
- color: Colors.white,
- onPressed: () => unawaited(
- _run(() => _controller!.setVolume(isMuted ? 1 : 0)),
- ),
- icon: Icon(
- isMuted ? Icons.volume_off : Icons.volume_up,
- ),
- ),
- IconButton(
- color: Colors.white,
- onPressed: () =>
- unawaited(_setFullscreen(!_isFullscreen)),
- icon: Icon(
- _isFullscreen
- ? Icons.fullscreen_exit
- : Icons.fullscreen,
- ),
- ),
- ],
- ),
+ child: const VideoBottomScrim(hasCaption: false),
+ ),
+ Listener(
+ // Long-press cancellation only fires before recognition in Flutter.
+ onPointerCancel: (_) => _stopLongPressSpeed(),
+ child: DoubleTapSeekOverlay(
+ enabled: () => _isPlaybackReady && !_hasError,
+ position: () => _seekController.position,
+ duration: () => _seekController.duration ?? Duration.zero,
+ seekBy: _seekController.seekBy,
+ onSingleTap: _toggleControls,
+ onSeekInteraction: () {
+ setState(() => _showControls = true);
+ _scheduleHideControls();
+ },
+ onLongPress: _startLongPressSpeed,
+ onLongPressUp: _stopLongPressSpeed,
+ onLongPressCancel: _stopLongPressSpeed,
+ ),
+ ),
+ IgnorePointer(
+ ignoring: !_showControls,
+ child: AnimatedOpacity(
+ opacity: _showControls ? 1 : 0,
+ duration: const Duration(milliseconds: 200),
+ curve: Curves.easeInQuad,
+ child: Center(child: PlayPauseButton(controller)),
+ ),
+ ),
+ GalleryBottomControlsPositioned(
+ bottom: kVideoProgressRowBottomInset,
+ child: SafeArea(
+ top: false,
+ child: IgnorePointer(
+ ignoring: !_showControls,
+ child: AnimatedOpacity(
+ opacity: _showControls ? 1 : 0,
+ duration: const Duration(milliseconds: 200),
+ curve: Curves.easeInQuad,
+ child: NativeVideoProgressControls(
+ controller,
+ _duration?.inSeconds,
+ _seekController,
+ muteButton: VideoMuteIconButton(
+ isMuted: isMuted,
+ onPressed: () => unawaited(
+ _run(() => controller.setVolume(isMuted ? 1 : 0)),
),
),
),
- ],
+ ),
),
),
),
- );
- }
-
- Duration _positionAt(double value) {
- final duration = _seekController.duration ?? Duration.zero;
- return Duration(milliseconds: (duration.inMilliseconds * value).round());
- }
-
- String _formatTime(Duration value) {
- final seconds = (value.inSeconds % 60).toString().padLeft(2, "0");
- return "${value.inMinutes}:$seconds";
+ ];
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 40ca797f9c..b3f5a3bb04 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -36,6 +36,7 @@ import 'package:photos/ui/viewer/actions/suggest_delete_sheet.dart';
import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/ui/viewer/file/video_control/video_speed_bottom_sheet.dart";
import "package:photos/ui/viewer/file/video_stream_change.dart";
+import "package:photos/ui/viewer/file/viewer_app_bar.dart";
import "package:photos/ui/viewer/file_details/favorite_widget.dart";
import "package:photos/ui/viewer/file_details/upload_icon_widget.dart";
import 'package:photos/utils/dialog_util.dart';
@@ -166,64 +167,20 @@ class FileAppBarState extends State<FileAppBar> {
_reloadActions = false;
}
final shouldShowActions = !isGuestView;
- return PreferredSize(
- preferredSize: const Size.fromHeight(kToolbarHeight),
- child: ValueListenableBuilder(
- valueListenable: widget.enableFullScreenNotifier,
- builder: (context, bool isFullScreen, child) {
- return IgnorePointer(
- ignoring: isFullScreen,
- child: AnimatedOpacity(
- opacity: isFullScreen ? 0 : 1,
- duration: const Duration(milliseconds: 150),
- child: child,
- ),
- );
+ return ValueListenableBuilder<bool>(
+ valueListenable: widget.enableFullScreenNotifier,
+ builder: (context, isFullScreen, _) => ViewerAppBar(
+ visible: !isFullScreen,
+ toolbarKey: ValueKey(isGuestView),
+ onBackPressed: () {
+ final onBackPressed = widget.onBackPressed;
+ if (onBackPressed != null && !isGuestView) {
+ unawaited(Future.sync(() => onBackPressed(context)));
+ return;
+ }
+ isGuestView ? _requestAuthentication() : Navigator.of(context).pop();
},
- child: Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [
- Colors.black.withValues(alpha: 0.72),
- Colors.black.withValues(alpha: 0.6),
- Colors.black.withValues(alpha: 0.05),
- Colors.black.withValues(alpha: 0.025),
- Colors.transparent,
- ],
- stops: const [0, 0.2, 0.9, 0.95, 1],
- ),
- ),
- child: SafeArea(
- child: AnimatedSwitcher(
- duration: const Duration(milliseconds: 250),
- switchInCurve: Curves.easeInOut,
- switchOutCurve: Curves.easeInOut,
- child: AppBar(
- clipBehavior: Clip.none,
- key: ValueKey(isGuestView),
- iconTheme: const IconThemeData(color: Colors.white),
- leading: IconButton(
- icon: const Icon(Icons.arrow_back),
- onPressed: () {
- final onBackPressed = widget.onBackPressed;
- if (onBackPressed != null && !isGuestView) {
- unawaited(Future.sync(() => onBackPressed(context)));
- return;
- }
- isGuestView
- ? _requestAuthentication()
- : Navigator.of(context).pop();
- },
- ),
- actions: shouldShowActions ? _actions : [],
- elevation: 0,
- backgroundColor: const Color(0x00000000),
- ),
- ),
- ),
- ),
+ actions: shouldShowActions ? _actions : [],
),
);
}
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.dart
index c4f0cea692..c3931c6302 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
@@ -7,17 +7,20 @@ import "package:photos/core/event_bus.dart";
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";
+import "package:photos/ui/viewer/file/video_control/mute_button.dart";
import "package:photos/ui/viewer/file/video_seek_controller.dart";
class NativeVideoProgressControls extends StatefulWidget {
final NativeVideoPlayerController controller;
final int? duration;
final VideoSeekController seekController;
+ final Widget muteButton;
const NativeVideoProgressControls(
this.controller,
this.duration,
this.seekController, {
+ this.muteButton = const VideoMuteButton(),
super.key,
});
@@ -122,6 +125,7 @@ class _NativeVideoProgressControlsState
);
return VideoProgressRow(
seekBar: seekBar,
+ muteButton: widget.muteButton,
elapsedTime: secondsToDuration(_elapsedMilliseconds ~/ 1000),
totalTime: secondsToDuration(
(_effectiveDurationInMilliseconds() ?? 0) ~/ 1000,
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.dart
index 6ff4289897..02502e5e4e 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
@@ -176,11 +176,13 @@ class VideoProgressRow extends StatelessWidget {
final Widget seekBar;
final String elapsedTime;
final String totalTime;
+ final Widget muteButton;
const VideoProgressRow({
required this.seekBar,
required this.elapsedTime,
required this.totalTime,
+ this.muteButton = const VideoMuteButton(),
super.key,
});
@@ -204,7 +206,7 @@ class VideoProgressRow extends StatelessWidget {
const SizedBox(width: 16),
Text('$elapsedTime / $totalTime', style: timeStyle),
const SizedBox(width: 7),
- const VideoMuteButton(),
+ muteButton,
],
),
),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_control/mute_button.dart b/mobile/apps/photos/lib/ui/viewer/file/video_control/mute_button.dart
index c3d9864095..d1a2fccf62 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_control/mute_button.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_control/mute_button.dart
@@ -36,6 +36,29 @@ class _VideoMuteButtonState extends State<VideoMuteButton> {
super.dispose();
}
+ @override
+ Widget build(BuildContext context) {
+ return VideoMuteIconButton(
+ isMuted: _isMuted,
+ onPressed: () async {
+ final newValue = !_isMuted;
+ await localSettings.setIsMuted(newValue);
+ Bus.instance.fire(VideoMuteChangedEvent(newValue));
+ },
+ );
+ }
+}
+
+class VideoMuteIconButton extends StatelessWidget {
+ final bool isMuted;
+ final VoidCallback onPressed;
+
+ const VideoMuteIconButton({
+ required this.isMuted,
+ required this.onPressed,
+ super.key,
+ });
+
@override
Widget build(BuildContext context) {
return SizedBox(
@@ -57,19 +80,15 @@ class _VideoMuteButtonState extends State<VideoMuteButton> {
switchInCurve: Curves.easeInOutQuart,
switchOutCurve: Curves.easeInOutQuart,
child: HugeIcon(
- key: ValueKey(_isMuted),
- icon: _isMuted
+ key: ValueKey(isMuted),
+ icon: isMuted
? HugeIcons.strokeRoundedVolumeOff
: HugeIcons.strokeRoundedVolumeHigh,
color: Colors.white,
size: 20,
),
),
- onPressed: () async {
- final newValue = !_isMuted;
- await localSettings.setIsMuted(newValue);
- Bus.instance.fire(VideoMuteChangedEvent(newValue));
- },
+ onPressed: onPressed,
),
);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/viewer_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/viewer_app_bar.dart
new file mode 100644
index 0000000000..bfc782fa33
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/file/viewer_app_bar.dart
@@ -0,0 +1,63 @@
+import "package:flutter/material.dart";
+
+class ViewerAppBar extends StatelessWidget {
+ final bool visible;
+ final VoidCallback onBackPressed;
+ final List<Widget> actions;
+ final Key? toolbarKey;
+
+ const ViewerAppBar({
+ required this.visible,
+ required this.onBackPressed,
+ this.actions = const [],
+ this.toolbarKey,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return IgnorePointer(
+ ignoring: !visible,
+ child: AnimatedOpacity(
+ opacity: visible ? 1 : 0,
+ duration: const Duration(milliseconds: 150),
+ child: Container(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [
+ Colors.black.withValues(alpha: 0.72),
+ Colors.black.withValues(alpha: 0.6),
+ Colors.black.withValues(alpha: 0.05),
+ Colors.black.withValues(alpha: 0.025),
+ Colors.transparent,
+ ],
+ stops: const [0, 0.2, 0.9, 0.95, 1],
+ ),
+ ),
+ child: SafeArea(
+ bottom: false,
+ child: AnimatedSwitcher(
+ duration: const Duration(milliseconds: 250),
+ switchInCurve: Curves.easeInOut,
+ switchOutCurve: Curves.easeInOut,
+ child: AppBar(
+ key: toolbarKey,
+ clipBehavior: Clip.none,
+ iconTheme: const IconThemeData(color: Colors.white),
+ leading: IconButton(
+ icon: const Icon(Icons.arrow_back),
+ onPressed: onBackPressed,
+ ),
+ actions: actions,
+ elevation: 0,
+ backgroundColor: Colors.transparent,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}