mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
fix: Update playback position when paused (#344)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
d1d7cbd74d
commit
aad081abae
2 changed files with 38 additions and 9 deletions
|
|
@ -37,11 +37,11 @@ class VideoPlayerNotifier extends StateNotifier<MediaControlsWrapper> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final subscription = state.stateStream?.listen((value) {
|
final subscription = state.stateStream?.listen((value) {
|
||||||
mediaState.update((state) => state.copyWith(buffering: value.buffering));
|
updateBuffering(value.buffering);
|
||||||
mediaState.update((state) => state.copyWith(buffer: value.buffer));
|
updateBuffer(value.buffer);
|
||||||
updatePlaying(value.playing);
|
updatePlaying(value.playing);
|
||||||
updatePosition(value.position);
|
updatePosition(value.position);
|
||||||
mediaState.update((state) => state.copyWith(duration: value.duration));
|
updateDuration(value.duration);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (subscription != null) {
|
if (subscription != null) {
|
||||||
|
|
@ -49,32 +49,58 @@ class VideoPlayerNotifier extends StateNotifier<MediaControlsWrapper> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateBuffering(bool event) async =>
|
||||||
|
mediaState.update((state) => state.buffering == event ? state : state.copyWith(buffering: event));
|
||||||
|
|
||||||
|
Future<void> updateBuffer(Duration buffer) async {
|
||||||
|
mediaState.update(
|
||||||
|
(state) => (state.buffer - buffer).inSeconds.abs() < 1
|
||||||
|
? state
|
||||||
|
: state.copyWith(
|
||||||
|
buffer: buffer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateDuration(Duration duration) async {
|
||||||
|
mediaState.update((state) {
|
||||||
|
return (state.duration - duration).inSeconds.abs() < 1
|
||||||
|
? state
|
||||||
|
: state.copyWith(
|
||||||
|
duration: duration,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> updatePlaying(bool event) async {
|
Future<void> updatePlaying(bool event) async {
|
||||||
if (!state.hasPlayer) return;
|
if (!state.hasPlayer) return;
|
||||||
mediaState.update((state) => state.copyWith(playing: event));
|
mediaState.update(
|
||||||
|
(state) => state.playing == event ? state : state.copyWith(playing: event),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updatePosition(Duration event) async {
|
Future<void> updatePosition(Duration event) async {
|
||||||
if (!state.hasPlayer) return;
|
if (!state.hasPlayer) return;
|
||||||
if (playbackState.playing == false) return;
|
if (playbackState.playing == false) return;
|
||||||
|
final currentState = playbackState;
|
||||||
|
final currentPosition = currentState.position;
|
||||||
|
|
||||||
|
if ((currentPosition - event).inSeconds.abs() < 1) return;
|
||||||
|
|
||||||
final position = event;
|
final position = event;
|
||||||
final lastPosition = ref.read(mediaPlaybackProvider.select((value) => value.lastPosition));
|
|
||||||
|
final lastPosition = currentState.lastPosition;
|
||||||
final diff = (position.inMilliseconds - lastPosition.inMilliseconds).abs();
|
final diff = (position.inMilliseconds - lastPosition.inMilliseconds).abs();
|
||||||
|
|
||||||
if (diff > const Duration(seconds: 10).inMilliseconds) {
|
if (diff > const Duration(seconds: 10).inMilliseconds) {
|
||||||
mediaState.update((value) => value.copyWith(
|
mediaState.update((value) => value.copyWith(
|
||||||
position: event,
|
position: event,
|
||||||
playing: playbackState.playing,
|
|
||||||
duration: playbackState.duration,
|
|
||||||
lastPosition: position,
|
lastPosition: position,
|
||||||
));
|
));
|
||||||
ref.read(playBackModel)?.updatePlaybackPosition(position, playbackState.playing, ref);
|
ref.read(playBackModel)?.updatePlaybackPosition(position, playbackState.playing, ref);
|
||||||
} else {
|
} else {
|
||||||
mediaState.update((value) => value.copyWith(
|
mediaState.update((value) => value.copyWith(
|
||||||
position: event,
|
position: event,
|
||||||
playing: playbackState.playing,
|
|
||||||
duration: playbackState.duration,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,9 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
||||||
@override
|
@override
|
||||||
Future<void> seek(Duration position) {
|
Future<void> seek(Duration position) {
|
||||||
_player?.seek(position);
|
_player?.seek(position);
|
||||||
|
if (_player?.lastState.playing == false) {
|
||||||
|
ref.read(mediaPlaybackProvider.notifier).update((state) => state.copyWith(position: position));
|
||||||
|
}
|
||||||
return super.seek(position);
|
return super.seek(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue