fix: Incorrect playback reporting (#221)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-02-08 17:05:53 +01:00 committed by GitHub
parent f259151336
commit 3b4b8a9101
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 27 deletions

View file

@ -204,6 +204,8 @@ class MediaControlsWrapper extends BaseAudioHandler {
processingState: AudioProcessingState.ready,
));
ref.read(playBackModel)?.playbackStarted(currentPosition ?? Duration.zero, ref);
return super.play();
}
@ -232,16 +234,22 @@ class MediaControlsWrapper extends BaseAudioHandler {
@override
Future<void> stop() async {
WakelockPlus.disable();
final position = _player?.lastState.position;
final totalDuration = _player?.lastState.duration;
super.stop();
_player?.stop();
final position = _player?.lastState.position;
final totalDuration = _player?.lastState.duration;
//Small delay so we don't post right after playback/progress update
await Future.delayed(const Duration(seconds: 1));
ref.read(playBackModel)?.playbackStopped(position ?? Duration.zero, totalDuration, ref);
ref.read(mediaPlaybackProvider.notifier).update((state) => state.copyWith(position: Duration.zero));
smtc?.setPlaybackStatus(PlaybackStatus.stopped);
smtc?.clearMetadata();
smtc?.disableSmtc();
playbackState.add(
playbackState.value.copyWith(
playing: false,