Skip to content

Commit

Permalink
🐛 Fix: index of item when shuffle enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
devaryakjha committed Oct 23, 2023
1 parent 37dd776 commit 2cf9f0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/cubits/player/player_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ class MediaPlayerCubit extends AppCubit<MediaPlayerState>

Future<void> playFromMediaPlaylist<T extends PlayableMedia>(
MediaPlaylist<T> playlist, [
int? startIndex,
PlayableMedia? initialMedia,
bool autoPlay = true,
]) async {
if (playlist.id == state.currentPlaylist && !audioHandler.player.playing) {
final startIndex = initialMedia == null
? null
: state.queueState.queue.indexOf(initialMedia.toMediaItem());
if (startIndex != null) {
await skipToIndex(startIndex, autoPlay);
} else if (autoPlay) {
Expand All @@ -76,6 +79,13 @@ class MediaPlayerCubit extends AppCubit<MediaPlayerState>
unawaited(_configCubit.saveCurrentPlaylist(playlist));
emit(state.copyWith(currentPlaylist: playlist.id));
await audioHandler.updateQueue(playlist.mediaItemsAsMediaItems);
final shuffleModeEnabled = audioHandler.player.shuffleModeEnabled;
if (shuffleModeEnabled) {
await audioHandler.setShuffleMode(AudioServiceShuffleMode.all);
}
final startIndex = initialMedia == null
? null
: state.queueState.queue.indexOf(initialMedia.toMediaItem());
if (startIndex != null) {
await skipToIndex(startIndex, autoPlay);
} else if (autoPlay) {
Expand Down
2 changes: 1 addition & 1 deletion lib/features/library/ui/library_widgets/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _LibraryContentState extends State<LibraryContent> {
} else {
context.readMediaPlayerCubit.playFromMediaPlaylist(
state.playlist.copyWith(mediaItems: sortedMediaItems),
index,
mediaItem,
);
}
},
Expand Down

0 comments on commit 2cf9f0e

Please sign in to comment.