Got hiding when tapped working

This commit is contained in:
Marty Fuhry
2024-03-04 11:32:00 -05:00
parent 2fdfee0162
commit 36d892289e
2 changed files with 46 additions and 66 deletions
@@ -56,13 +56,6 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
(_, state) { (_, state) {
// Show buffering // Show buffering
showBuffering.value = state == VideoPlaybackState.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 /// Toggles between playing and pausing depending on the state of the video
@@ -72,6 +65,7 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
} }
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: showControlsAndStartHideTimer, onTap: showControlsAndStartHideTimer,
child: AbsorbPointer( child: AbsorbPointer(
absorbing: !ref.watch(showControlsProvider), absorbing: !ref.watch(showControlsProvider),
@@ -82,12 +76,14 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
child: DelayedLoadingIndicator( child: DelayedLoadingIndicator(
fadeInDuration: Duration(milliseconds: 400), fadeInDuration: Duration(milliseconds: 400),
), ),
), )
else
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (state != VideoPlaybackState.playing) { if (state != VideoPlaybackState.playing) {
togglePlay(); togglePlay();
} }
ref.read(showControlsProvider.notifier).show = false;
}, },
child: CenterPlayButton( child: CenterPlayButton(
backgroundColor: Colors.black54, backgroundColor: Colors.black54,
@@ -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 // Adds and removes the listener to the video player
useEffect( useEffect(
() { () {
@@ -135,13 +126,7 @@ class VideoViewerPage extends HookConsumerWidget {
); );
final size = MediaQuery.of(context).size; final size = MediaQuery.of(context).size;
return GestureDetector( return PopScope(
onTap: () {
if (ref.read(showControlsProvider)) {
ref.read(showControlsProvider.notifier).show = false;
}
},
child: PopScope(
onPopInvoked: (pop) { onPopInvoked: (pop) {
ref.read(videoPlaybackValueProvider.notifier).value = ref.read(videoPlaybackValueProvider.notifier).value =
VideoPlaybackValue.uninitialized(); VideoPlaybackValue.uninitialized();
@@ -176,7 +161,6 @@ class VideoViewerPage extends HookConsumerWidget {
], ],
), ),
), ),
),
); );
} }
} }