diff --git a/lib/cubits/player/player_cubit.dart b/lib/cubits/player/player_cubit.dart index 31e5f83..efce673 100644 --- a/lib/cubits/player/player_cubit.dart +++ b/lib/cubits/player/player_cubit.dart @@ -62,10 +62,13 @@ class MediaPlayerCubit extends AppCubit Future playFromMediaPlaylist( MediaPlaylist 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) { @@ -76,6 +79,13 @@ class MediaPlayerCubit extends AppCubit 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) { diff --git a/lib/features/library/ui/library_widgets/page.dart b/lib/features/library/ui/library_widgets/page.dart index 4939ab0..fc79c11 100644 --- a/lib/features/library/ui/library_widgets/page.dart +++ b/lib/features/library/ui/library_widgets/page.dart @@ -162,7 +162,7 @@ class _LibraryContentState extends State { } else { context.readMediaPlayerCubit.playFromMediaPlaylist( state.playlist.copyWith(mediaItems: sortedMediaItems), - index, + mediaItem, ); } },