fixing issues with sync between controls
This commit is contained in:
@@ -31,6 +31,7 @@ ChewieController? useChewieController(
|
|||||||
}) {
|
}) {
|
||||||
return use(
|
return use(
|
||||||
_ChewieControllerHook(
|
_ChewieControllerHook(
|
||||||
|
keys: [asset],
|
||||||
asset: asset,
|
asset: asset,
|
||||||
placeholder: placeholder,
|
placeholder: placeholder,
|
||||||
showOptions: showOptions,
|
showOptions: showOptions,
|
||||||
@@ -66,6 +67,7 @@ class _ChewieControllerHook extends Hook<ChewieController?> {
|
|||||||
final VoidCallback? onVideoEnded;
|
final VoidCallback? onVideoEnded;
|
||||||
|
|
||||||
const _ChewieControllerHook({
|
const _ChewieControllerHook({
|
||||||
|
super.keys,
|
||||||
required this.asset,
|
required this.asset,
|
||||||
this.controlsSafeAreaMinimum = const EdgeInsets.only(
|
this.controlsSafeAreaMinimum = const EdgeInsets.only(
|
||||||
bottom: 100,
|
bottom: 100,
|
||||||
@@ -94,7 +96,7 @@ class _ChewieControllerHookState
|
|||||||
VideoPlayerController? videoPlayerController;
|
VideoPlayerController? videoPlayerController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initHook() async {
|
void initHook() {
|
||||||
super.initHook();
|
super.initHook();
|
||||||
_initialize().whenComplete(() => setState(() {}));
|
_initialize().whenComplete(() => setState(() {}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ class VideoPlayerControls extends StateNotifier<VideoPlaybackControls> {
|
|||||||
state = value;
|
state = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
state = VideoPlaybackControls(
|
||||||
|
position: 0,
|
||||||
|
pause: false,
|
||||||
|
mute: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
double get position => state.position;
|
double get position => state.position;
|
||||||
bool get mute => state.mute;
|
bool get mute => state.mute;
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
|
|||||||
/// Toggles between playing and pausing depending on the state of the video
|
/// Toggles between playing and pausing depending on the state of the video
|
||||||
void togglePlay() {
|
void togglePlay() {
|
||||||
showControlsAndStartHideTimer();
|
showControlsAndStartHideTimer();
|
||||||
ref.read(videoPlayerControlsProvider.notifier).togglePlay();
|
final state = ref.read(videoPlaybackValueProvider).state;
|
||||||
|
if (state == VideoPlaybackState.playing) {
|
||||||
|
ref.read(videoPlayerControlsProvider.notifier).pause();
|
||||||
|
} else {
|
||||||
|
ref.read(videoPlayerControlsProvider.notifier).play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ class GalleryViewerPage extends HookConsumerWidget {
|
|||||||
child: VideoViewerPage(
|
child: VideoViewerPage(
|
||||||
key: ValueKey(a),
|
key: ValueKey(a),
|
||||||
asset: a,
|
asset: a,
|
||||||
isMotionVideo: isPlayingVideo.value,
|
isMotionVideo: a.livePhotoVideoId != null,
|
||||||
placeholder: Image(
|
placeholder: Image(
|
||||||
image: provider,
|
image: provider,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
|
|||||||
@@ -96,8 +96,12 @@ class VideoViewerPage extends HookConsumerWidget {
|
|||||||
|
|
||||||
// Enable the WakeLock while the video is playing
|
// Enable the WakeLock while the video is playing
|
||||||
if (state == VideoPlaybackState.playing) {
|
if (state == VideoPlaybackState.playing) {
|
||||||
|
// Sync with the controls playing
|
||||||
|
ref.read(videoPlayerControlsProvider.notifier).play();
|
||||||
WakelockPlus.enable();
|
WakelockPlus.enable();
|
||||||
} else {
|
} else {
|
||||||
|
// Sync with the controls pause
|
||||||
|
ref.read(videoPlayerControlsProvider.notifier).pause();
|
||||||
WakelockPlus.disable();
|
WakelockPlus.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,9 +117,10 @@ class VideoViewerPage extends HookConsumerWidget {
|
|||||||
// Hide the controls
|
// Hide the controls
|
||||||
// Done in a microtask to avoid setting the state while the widget is building
|
// Done in a microtask to avoid setting the state while the widget is building
|
||||||
if (!isMotionVideo) {
|
if (!isMotionVideo) {
|
||||||
Future.microtask(
|
Future.microtask(() {
|
||||||
() => ref.read(showControlsProvider.notifier).show = false,
|
ref.read(showControlsProvider.notifier).show = false;
|
||||||
);
|
ref.read(videoPlayerControlsProvider.notifier).reset();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final video = controller.videoPlayerController.value;
|
final video = controller.videoPlayerController.value;
|
||||||
@@ -127,8 +132,8 @@ class VideoViewerPage extends HookConsumerWidget {
|
|||||||
controller.videoPlayerController.addListener(updateVideoPlayback);
|
controller.videoPlayerController.addListener(updateVideoPlayback);
|
||||||
return () {
|
return () {
|
||||||
// Removes listener when we dispose
|
// Removes listener when we dispose
|
||||||
controller.pause();
|
|
||||||
controller.videoPlayerController.removeListener(updateVideoPlayback);
|
controller.videoPlayerController.removeListener(updateVideoPlayback);
|
||||||
|
controller.pause();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[controller],
|
[controller],
|
||||||
|
|||||||
Reference in New Issue
Block a user