diff --git a/lib/provider/Playback.dart b/lib/provider/Playback.dart index e7207fd6e..ffe755c01 100644 --- a/lib/provider/Playback.dart +++ b/lib/provider/Playback.dart @@ -202,6 +202,7 @@ class Playback extends PersistedChangeNotifier { if (index < 0 || index > playlist.tracks.length - 1) return; if (isPlaying || status == PlaybackStatus.playing) await stop(); this.playlist = playlist; + mobileAudioService?.session?.setActive(true); final played = this.playlist!.tracks[index]; status = PlaybackStatus.loading; notifyListeners(); @@ -320,6 +321,7 @@ class Playback extends PersistedChangeNotifier { } Future stop() async { + mobileAudioService?.session?.setActive(false); await player.stop(); await player.release(); isPlaying = false; @@ -634,6 +636,7 @@ class Playback extends PersistedChangeNotifier { (playlist!.trackIds.indexOf(track!.id!) + 1).toInt(); // checking if there's any track available forward if (nextTrackIndex > (playlist?.tracks.length ?? 0) - 1) return; + await pause(); await play(playlist!.tracks.elementAt(nextTrackIndex)).then((_) { playlist!.tracks[nextTrackIndex] = track!; }); @@ -645,6 +648,7 @@ class Playback extends PersistedChangeNotifier { (playlist!.trackIds.indexOf(track!.id!) - 1).toInt(); // checking if there's any track available behind if (prevTrackIndex < 0) return; + await pause(); await play(playlist!.tracks.elementAt(prevTrackIndex)).then((_) { playlist!.tracks[prevTrackIndex] = track!; }); diff --git a/lib/services/MobileAudioService.dart b/lib/services/MobileAudioService.dart index 87109ef83..9f999f537 100644 --- a/lib/services/MobileAudioService.dart +++ b/lib/services/MobileAudioService.dart @@ -18,18 +18,18 @@ class MobileAudioService extends BaseAudioHandler { } }); }); - final _player = playback.player; - _player.onPlayerStateChanged.listen((state) async { + final player = playback.player; + player.onPlayerStateChanged.listen((state) async { if (state != PlayerState.completed) { playbackState.add(await _transformEvent()); } }); - _player.onPositionChanged.listen((pos) async { + player.onPositionChanged.listen((pos) async { playbackState.add(await _transformEvent()); }); - _player.onPlayerComplete.listen((_) { + player.onPlayerComplete.listen((_) { if (playback.playlist == null && playback.track == null) { playbackState.add( PlaybackState( @@ -56,7 +56,6 @@ class MobileAudioService extends BaseAudioHandler { @override Future stop() async { - await session?.setActive(true); await playback.stop(); }