mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
chore(playback): re-enable shuffling
This commit is contained in:
parent
8bcce9282e
commit
696eeee882
@ -82,6 +82,17 @@ mixin NextFetcher on StateNotifier<ProxyPlaylist> {
|
||||
}
|
||||
}
|
||||
|
||||
List<Track> mapSourcesToTracks(List<String> sources) {
|
||||
final tracks = state.tracks;
|
||||
|
||||
return sources.map((source) {
|
||||
final track = tracks.firstWhereOrNull(
|
||||
(track) => makeAppropriateSource(track) == source,
|
||||
);
|
||||
return track!;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// This method must be called after any playback operation as
|
||||
/// it can increase the latency
|
||||
Future<void> storeTrack(Track track, SpotubeTrack spotubeTrack) async {
|
||||
|
@ -58,16 +58,34 @@ class ProxyPlaylistNotifier extends StateNotifier<ProxyPlaylist>
|
||||
audioPlayer.currentIndexChangedStream.listen((index) async {
|
||||
if (index == -1 || index == state.active) return;
|
||||
|
||||
final track = state.tracks.elementAtOrNull(index);
|
||||
if (track == null) return;
|
||||
notificationService.addTrack(track);
|
||||
state = state.copyWith(active: index);
|
||||
final newIndexedTrack =
|
||||
mapSourcesToTracks([audioPlayer.sources[index]]).firstOrNull;
|
||||
|
||||
if (newIndexedTrack == null) return;
|
||||
notificationService.addTrack(newIndexedTrack);
|
||||
state = state.copyWith(
|
||||
active: state.tracks
|
||||
.toList()
|
||||
.indexWhere((element) => element.id == newIndexedTrack.id),
|
||||
);
|
||||
|
||||
if (preferences.albumColorSync) {
|
||||
updatePalette();
|
||||
}
|
||||
});
|
||||
|
||||
audioPlayer.shuffledStream.listen((event) {
|
||||
final newlyOrderedTracks = mapSourcesToTracks(audioPlayer.sources);
|
||||
final newIndex = newlyOrderedTracks.indexWhere(
|
||||
(element) => element.id == state.activeTrack?.id,
|
||||
);
|
||||
|
||||
state = state.copyWith(
|
||||
tracks: newlyOrderedTracks.toSet(),
|
||||
active: newIndex,
|
||||
);
|
||||
});
|
||||
|
||||
bool isPreSearching = false;
|
||||
audioPlayer.percentCompletedStream(60).listen((percent) async {
|
||||
if (isPreSearching) return;
|
||||
|
@ -85,8 +85,6 @@ class MkPlayerWithState extends Player {
|
||||
@override
|
||||
Future<void> setShuffle(bool shuffle) async {
|
||||
_shuffled = shuffle;
|
||||
await super.setShuffle(shuffle);
|
||||
_shuffleStream.add(shuffle);
|
||||
if (shuffle) {
|
||||
_tempMedias = _playlist!.medias;
|
||||
final active = _playlist!.medias[_playlist!.index];
|
||||
@ -105,6 +103,8 @@ class MkPlayerWithState extends Player {
|
||||
);
|
||||
_tempMedias = null;
|
||||
}
|
||||
await super.setShuffle(shuffle);
|
||||
_shuffleStream.add(shuffle);
|
||||
}
|
||||
|
||||
@override
|
||||
|
Loading…
Reference in New Issue
Block a user