From 36d892289e5ca53f1f275c13f3f1dfc59af3fa0e Mon Sep 17 00:00:00 2001 From: Marty Fuhry Date: Mon, 4 Mar 2024 11:32:00 -0500 Subject: [PATCH] Got hiding when tapped working --- .../ui/custom_video_player_controls.dart | 40 +++++------ .../asset_viewer/views/video_viewer_page.dart | 72 ++++++++----------- 2 files changed, 46 insertions(+), 66 deletions(-) diff --git a/mobile/lib/modules/asset_viewer/ui/custom_video_player_controls.dart b/mobile/lib/modules/asset_viewer/ui/custom_video_player_controls.dart index ea6cc8f280..683c255b67 100644 --- a/mobile/lib/modules/asset_viewer/ui/custom_video_player_controls.dart +++ b/mobile/lib/modules/asset_viewer/ui/custom_video_player_controls.dart @@ -56,13 +56,6 @@ class CustomVideoPlayerControls extends HookConsumerWidget { (_, state) { // Show buffering showBuffering.value = state == VideoPlaybackState.buffering; - - // Synchronize player with video state - if (state == VideoPlaybackState.playing) { - ref.read(videoPlayerControlsProvider.notifier).play(); - } else if (state == VideoPlaybackState.paused) { - ref.read(videoPlayerControlsProvider.notifier).pause(); - } }); /// Toggles between playing and pausing depending on the state of the video @@ -72,6 +65,7 @@ class CustomVideoPlayerControls extends HookConsumerWidget { } return GestureDetector( + behavior: HitTestBehavior.opaque, onTap: showControlsAndStartHideTimer, child: AbsorbPointer( absorbing: !ref.watch(showControlsProvider), @@ -82,22 +76,24 @@ class CustomVideoPlayerControls extends HookConsumerWidget { child: DelayedLoadingIndicator( fadeInDuration: Duration(milliseconds: 400), ), + ) + else + GestureDetector( + onTap: () { + if (state != VideoPlaybackState.playing) { + togglePlay(); + } + ref.read(showControlsProvider.notifier).show = false; + }, + child: CenterPlayButton( + backgroundColor: Colors.black54, + iconColor: Colors.white, + isFinished: state == VideoPlaybackState.completed, + isPlaying: state == VideoPlaybackState.playing, + show: ref.watch(showControlsProvider), + onPressed: togglePlay, + ), ), - GestureDetector( - onTap: () { - if (state != VideoPlaybackState.playing) { - togglePlay(); - } - }, - child: CenterPlayButton( - backgroundColor: Colors.black54, - iconColor: Colors.white, - isFinished: state == VideoPlaybackState.completed, - isPlaying: state == VideoPlaybackState.playing, - show: ref.watch(showControlsProvider), - onPressed: togglePlay, - ), - ), ], ), ), diff --git a/mobile/lib/modules/asset_viewer/views/video_viewer_page.dart b/mobile/lib/modules/asset_viewer/views/video_viewer_page.dart index 76ce79095d..3206a566ac 100644 --- a/mobile/lib/modules/asset_viewer/views/video_viewer_page.dart +++ b/mobile/lib/modules/asset_viewer/views/video_viewer_page.dart @@ -102,15 +102,6 @@ class VideoViewerPage extends HookConsumerWidget { ); } - // Hide the controls when we load - useEffect( - () { - ref.read(showControlsProvider.notifier).show = false; - return null; - }, - [], - ); - // Adds and removes the listener to the video player useEffect( () { @@ -135,46 +126,39 @@ class VideoViewerPage extends HookConsumerWidget { ); final size = MediaQuery.of(context).size; - return GestureDetector( - onTap: () { - if (ref.read(showControlsProvider)) { - ref.read(showControlsProvider.notifier).show = false; - } + return PopScope( + onPopInvoked: (pop) { + ref.read(videoPlaybackValueProvider.notifier).value = + VideoPlaybackValue.uninitialized(); }, - child: PopScope( - onPopInvoked: (pop) { - ref.read(videoPlaybackValueProvider.notifier).value = - VideoPlaybackValue.uninitialized(); - }, - child: AnimatedSwitcher( - duration: const Duration(milliseconds: 400), - child: Stack( - children: [ - Visibility( - visible: controller == null, - child: Stack( - children: [ - if (placeholder != null) placeholder!, - const Positioned.fill( - child: Center( - child: DelayedLoadingIndicator( - fadeInDuration: Duration(milliseconds: 500), - ), + child: AnimatedSwitcher( + duration: const Duration(milliseconds: 400), + child: Stack( + children: [ + Visibility( + visible: controller == null, + child: Stack( + children: [ + if (placeholder != null) placeholder!, + const Positioned.fill( + child: Center( + child: DelayedLoadingIndicator( + fadeInDuration: Duration(milliseconds: 500), ), ), - ], + ), + ], + ), + ), + if (controller != null) + SizedBox( + height: size.height, + width: size.width, + child: Chewie( + controller: controller, ), ), - if (controller != null) - SizedBox( - height: size.height, - width: size.width, - child: Chewie( - controller: controller, - ), - ), - ], - ), + ], ), ), );