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

View File

@@ -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,
),
),
],
),
),

View File

@@ -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,
),
),
],
),
],
),
),
);