From ed29ab5137416d9fb2e7e9fe840f56ef52df6f61 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 4 Jun 2023 12:30:04 +0600 Subject: [PATCH] fix: cached queue tracks expired stream --- lib/models/spotube_track.dart | 2 ++ lib/provider/proxy_playlist/proxy_playlist.dart | 4 +--- lib/provider/proxy_playlist/proxy_playlist_provider.dart | 8 ++++++-- lib/services/audio_player/mk_state_player.dart | 2 +- lib/services/audio_services/linux_audio_service.dart | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/models/spotube_track.dart b/lib/models/spotube_track.dart index 25418a191..da0d49449 100644 --- a/lib/models/spotube_track.dart +++ b/lib/models/spotube_track.dart @@ -237,6 +237,7 @@ class SpotubeTrack extends Track { Map toJson() { return { + // super values "album": album?.toJson(), "artists": artists?.map((artist) => artist.toJson()).toList(), "availableMarkets": availableMarkets, @@ -253,6 +254,7 @@ class SpotubeTrack extends Track { "trackNumber": trackNumber, "type": type, "uri": uri, + // this values "ytTrack": ytTrack.toJson(), "ytUri": ytUri, "siblings": siblings.map((sibling) => sibling.toJson()).toList(), diff --git a/lib/provider/proxy_playlist/proxy_playlist.dart b/lib/provider/proxy_playlist/proxy_playlist.dart index 287a43223..2461f4b69 100644 --- a/lib/provider/proxy_playlist/proxy_playlist.dart +++ b/lib/provider/proxy_playlist/proxy_playlist.dart @@ -46,9 +46,7 @@ class ProxyPlaylist { } static Map _makeAppropriateTrackJson(Track track) { - if (track is SpotubeTrack) { - return track.toJson(); - } else if (track is LocalTrack) { + if (track is LocalTrack) { return track.toJson(); } else { return track.toJson(); diff --git a/lib/provider/proxy_playlist/proxy_playlist_provider.dart b/lib/provider/proxy_playlist/proxy_playlist_provider.dart index f7324457a..927abd6a7 100644 --- a/lib/provider/proxy_playlist/proxy_playlist_provider.dart +++ b/lib/provider/proxy_playlist/proxy_playlist_provider.dart @@ -44,6 +44,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier late final AudioServices notificationService; UserPreferences get preferences => ref.read(userPreferencesProvider); + ProxyPlaylist get playlist => state; BlackListNotifier get blacklist => ref.read(BlackListNotifier.provider.notifier); @@ -96,7 +97,8 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier }); bool isPreSearching = false; - audioPlayer.percentCompletedStream(60).listen((percent) async { + + listenTo60Percent(percent) async { if (isPreSearching || audioPlayer.currentSource == null) return; try { isPreSearching = true; @@ -130,7 +132,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier } finally { isPreSearching = false; } - }); + } + + audioPlayer.percentCompletedStream(60).listen(listenTo60Percent); // player stops at 99% if nextSource is still not playable audioPlayer.percentCompletedStream(99).listen((_) async { diff --git a/lib/services/audio_player/mk_state_player.dart b/lib/services/audio_player/mk_state_player.dart index de9453576..b7732f1a8 100644 --- a/lib/services/audio_player/mk_state_player.dart +++ b/lib/services/audio_player/mk_state_player.dart @@ -52,7 +52,7 @@ class MkPlayerWithState extends Player { await super.open(_playlist!.medias[_playlist!.index], play: true); } else { await next(); - await play(); + await Future.delayed(const Duration(milliseconds: 250), play); } }), streams.playlist.listen((event) { diff --git a/lib/services/audio_services/linux_audio_service.dart b/lib/services/audio_services/linux_audio_service.dart index 661bf5a6f..b50e4ee4d 100644 --- a/lib/services/audio_services/linux_audio_service.dart +++ b/lib/services/audio_services/linux_audio_service.dart @@ -239,7 +239,7 @@ class _MprisMediaPlayer2Player extends DBusObject { }()); } - ProxyPlaylist get playlist => playlistNotifier.state; + ProxyPlaylist get playlist => playlistNotifier.playlist; void dispose() { dbus.unregisterObject(this);