mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 06:31:58 +00:00
fix looping
This commit is contained in:
parent
b15e01e2b6
commit
d414c2789a
5 changed files with 52 additions and 52 deletions
|
@ -37,11 +37,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final loopVideo = ref.watch(
|
|
||||||
appSettingsServiceProvider.select(
|
|
||||||
(settings) => settings.getSetting<bool>(AppSettingsEnum.loopVideo),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final controller = useState<NativeVideoPlayerController?>(null);
|
final controller = useState<NativeVideoPlayerController?>(null);
|
||||||
final lastVideoPosition = useRef(-1);
|
final lastVideoPosition = useRef(-1);
|
||||||
final isBuffering = useRef(false);
|
final isBuffering = useRef(false);
|
||||||
|
@ -186,28 +181,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
interval: const Duration(milliseconds: 100),
|
interval: const Duration(milliseconds: 100),
|
||||||
maxWaitTime: const Duration(milliseconds: 200),
|
maxWaitTime: const Duration(milliseconds: 200),
|
||||||
);
|
);
|
||||||
ref.listen(videoPlayerControlsProvider.select((value) => value.position),
|
Future<void> onPlayerControlsPlayChange(bool? _, bool pause) async {
|
||||||
(_, position) async {
|
|
||||||
final playerController = controller.value;
|
|
||||||
if (playerController == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final playbackInfo = playerController.playbackInfo;
|
|
||||||
if (playbackInfo == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the position to seek to
|
|
||||||
final seek = position ~/ 1;
|
|
||||||
if (seek != playbackInfo.position) {
|
|
||||||
seekDebouncer.run(() => playerController.seekTo(seek));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// // When the custom video controls pause or play
|
|
||||||
ref.listen(videoPlayerControlsProvider.select((value) => value.pause),
|
|
||||||
(_, pause) async {
|
|
||||||
final videoController = controller.value;
|
final videoController = controller.value;
|
||||||
if (videoController == null || !context.mounted) {
|
if (videoController == null || !context.mounted) {
|
||||||
return;
|
return;
|
||||||
|
@ -228,8 +202,39 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.severe('Error pausing or playing video: $error');
|
log.severe('Error pausing or playing video: $error');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.listen(videoPlayerControlsProvider.select((value) => value.position),
|
||||||
|
(_, position) {
|
||||||
|
final playerController = controller.value;
|
||||||
|
if (playerController == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final playbackInfo = playerController.playbackInfo;
|
||||||
|
if (playbackInfo == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the position to seek to
|
||||||
|
final seek = position ~/ 1;
|
||||||
|
if (seek != playbackInfo.position) {
|
||||||
|
seekDebouncer.run(() => playerController.seekTo(seek));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isIOS &&
|
||||||
|
seek == 0 &&
|
||||||
|
!ref.read(videoPlayerControlsProvider.notifier).paused) {
|
||||||
|
onPlayerControlsPlayChange(null, false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// // When the custom video controls pause or play
|
||||||
|
ref.listen(
|
||||||
|
videoPlayerControlsProvider.select((value) => value.pause),
|
||||||
|
onPlayerControlsPlayChange,
|
||||||
|
);
|
||||||
|
|
||||||
void onPlaybackReady() async {
|
void onPlaybackReady() async {
|
||||||
final videoController = controller.value;
|
final videoController = controller.value;
|
||||||
if (videoController == null || !isCurrent || !context.mounted) {
|
if (videoController == null || !isCurrent || !context.mounted) {
|
||||||
|
@ -258,12 +263,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
|
|
||||||
final videoPlayback =
|
final videoPlayback =
|
||||||
VideoPlaybackValue.fromNativeController(videoController);
|
VideoPlaybackValue.fromNativeController(videoController);
|
||||||
// No need to update the UI when it's about to loop
|
|
||||||
if (videoPlayback.state == VideoPlaybackState.completed && loopVideo) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ref.read(videoPlaybackValueProvider.notifier).status =
|
|
||||||
videoPlayback.state;
|
|
||||||
if (videoPlayback.state == VideoPlaybackState.playing) {
|
if (videoPlayback.state == VideoPlaybackState.playing) {
|
||||||
// Sync with the controls playing
|
// Sync with the controls playing
|
||||||
WakelockPlus.enable();
|
WakelockPlus.enable();
|
||||||
|
@ -271,6 +270,9 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
// Sync with the controls pause
|
// Sync with the controls pause
|
||||||
WakelockPlus.disable();
|
WakelockPlus.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref.read(videoPlaybackValueProvider.notifier).status =
|
||||||
|
videoPlayback.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPlaybackPositionChanged() {
|
void onPlaybackPositionChanged() {
|
||||||
|
@ -302,28 +304,16 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPlaybackEnded() {
|
|
||||||
final videoController = controller.value;
|
|
||||||
if (videoController == null || !context.mounted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!loopVideo) {
|
|
||||||
WakelockPlus.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeListeners(NativeVideoPlayerController controller) {
|
void removeListeners(NativeVideoPlayerController controller) {
|
||||||
controller.onPlaybackPositionChanged
|
controller.onPlaybackPositionChanged
|
||||||
.removeListener(onPlaybackPositionChanged);
|
.removeListener(onPlaybackPositionChanged);
|
||||||
controller.onPlaybackStatusChanged
|
controller.onPlaybackStatusChanged
|
||||||
.removeListener(onPlaybackStatusChanged);
|
.removeListener(onPlaybackStatusChanged);
|
||||||
controller.onPlaybackReady.removeListener(onPlaybackReady);
|
controller.onPlaybackReady.removeListener(onPlaybackReady);
|
||||||
controller.onPlaybackEnded.removeListener(onPlaybackEnded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initController(NativeVideoPlayerController nc) async {
|
void initController(NativeVideoPlayerController nc) async {
|
||||||
if (controller.value != null) {
|
if (controller.value != null || !context.mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ref.read(videoPlayerControlsProvider.notifier).reset();
|
ref.read(videoPlayerControlsProvider.notifier).reset();
|
||||||
|
@ -337,10 +327,15 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
nc.onPlaybackPositionChanged.addListener(onPlaybackPositionChanged);
|
nc.onPlaybackPositionChanged.addListener(onPlaybackPositionChanged);
|
||||||
nc.onPlaybackStatusChanged.addListener(onPlaybackStatusChanged);
|
nc.onPlaybackStatusChanged.addListener(onPlaybackStatusChanged);
|
||||||
nc.onPlaybackReady.addListener(onPlaybackReady);
|
nc.onPlaybackReady.addListener(onPlaybackReady);
|
||||||
nc.onPlaybackEnded.addListener(onPlaybackEnded);
|
|
||||||
|
|
||||||
|
nc.loadVideoSource(source).catchError((error) {
|
||||||
|
log.severe('Error loading video source: $error');
|
||||||
|
});
|
||||||
|
final loopVideo = ref
|
||||||
|
.read(appSettingsServiceProvider)
|
||||||
|
.getSetting<bool>(AppSettingsEnum.loopVideo);
|
||||||
nc.setLoop(loopVideo);
|
nc.setLoop(loopVideo);
|
||||||
nc.loadVideoSource(source);
|
|
||||||
controller.value = nc;
|
controller.value = nc;
|
||||||
Timer(const Duration(milliseconds: 200), checkIfBuffering);
|
Timer(const Duration(milliseconds: 200), checkIfBuffering);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/providers/asset_viewer/video_player_value_provider.dart';
|
||||||
|
|
||||||
class VideoPlaybackControls {
|
class VideoPlaybackControls {
|
||||||
const VideoPlaybackControls({
|
const VideoPlaybackControls({
|
||||||
|
@ -40,6 +41,7 @@ class VideoPlayerControls extends StateNotifier<VideoPlaybackControls> {
|
||||||
|
|
||||||
double get position => state.position;
|
double get position => state.position;
|
||||||
bool get mute => state.mute;
|
bool get mute => state.mute;
|
||||||
|
bool get paused => state.pause;
|
||||||
|
|
||||||
set position(double value) {
|
set position(double value) {
|
||||||
if (state.position == value) {
|
if (state.position == value) {
|
||||||
|
@ -111,5 +113,6 @@ class VideoPlayerControls extends StateNotifier<VideoPlaybackControls> {
|
||||||
mute: state.mute,
|
mute: state.mute,
|
||||||
pause: false,
|
pause: false,
|
||||||
);
|
);
|
||||||
|
ref.read(videoPlaybackValueProvider.notifier).position = Duration.zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,9 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not hide on paused
|
// Do not hide on paused
|
||||||
if (state != VideoPlaybackState.paused && assetIsVideo) {
|
if (state != VideoPlaybackState.paused &&
|
||||||
|
state != VideoPlaybackState.completed &&
|
||||||
|
assetIsVideo) {
|
||||||
ref.read(showControlsProvider.notifier).show = false;
|
ref.read(showControlsProvider.notifier).show = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1028,8 +1028,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "feat/exoplayer"
|
ref: "68ea203"
|
||||||
resolved-ref: "2139230b334b22b87de1dba47cc5632e5d172840"
|
resolved-ref: "68ea2030ba7aceb1bc44b683ff0b742fd1a52d2f"
|
||||||
url: "https://github.com/immich-app/native_video_player"
|
url: "https://github.com/immich-app/native_video_player"
|
||||||
source: git
|
source: git
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
|
|
|
@ -67,7 +67,7 @@ dependencies:
|
||||||
native_video_player:
|
native_video_player:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/immich-app/native_video_player
|
url: https://github.com/immich-app/native_video_player
|
||||||
ref: feat/exoplayer
|
ref: 68ea203
|
||||||
|
|
||||||
#image editing packages
|
#image editing packages
|
||||||
crop_image: ^1.0.13
|
crop_image: ^1.0.13
|
||||||
|
|
Loading…
Reference in a new issue