Skip to content

Commit

Permalink
fix: cached queue tracks expired stream
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 4, 2023
1 parent f7ca3a6 commit ed29ab5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/models/spotube_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class SpotubeTrack extends Track {

Map<String, dynamic> toJson() {
return {
// super values
"album": album?.toJson(),
"artists": artists?.map((artist) => artist.toJson()).toList(),
"availableMarkets": availableMarkets,
Expand All @@ -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(),
Expand Down
4 changes: 1 addition & 3 deletions lib/provider/proxy_playlist/proxy_playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class ProxyPlaylist {
}

static Map<String, dynamic> _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();
Expand Down
8 changes: 6 additions & 2 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
late final AudioServices notificationService;

UserPreferences get preferences => ref.read(userPreferencesProvider);
ProxyPlaylist get playlist => state;
BlackListNotifier get blacklist =>
ref.read(BlackListNotifier.provider.notifier);

Expand Down Expand Up @@ -96,7 +97,8 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
});

bool isPreSearching = false;
audioPlayer.percentCompletedStream(60).listen((percent) async {

listenTo60Percent(percent) async {
if (isPreSearching || audioPlayer.currentSource == null) return;
try {
isPreSearching = true;
Expand Down Expand Up @@ -130,7 +132,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
} finally {
isPreSearching = false;
}
});
}

audioPlayer.percentCompletedStream(60).listen(listenTo60Percent);

// player stops at 99% if nextSource is still not playable
audioPlayer.percentCompletedStream(99).listen((_) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/audio_player/mk_state_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/audio_services/linux_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class _MprisMediaPlayer2Player extends DBusObject {
}());
}

ProxyPlaylist get playlist => playlistNotifier.state;
ProxyPlaylist get playlist => playlistNotifier.playlist;

void dispose() {
dbus.unregisterObject(this);
Expand Down

0 comments on commit ed29ab5

Please sign in to comment.