Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shuffle always starts on first song(issues:#61) and remove redund… #442

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -70,6 +72,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
audioServiceHelper.replaceQueueWithItem(
itemList: items,
shuffle: true,
initialIndex: Random().nextInt(items.length),
),
icon: const Icon(Icons.shuffle),
label: Text(
Expand Down
16 changes: 8 additions & 8 deletions lib/services/audio_service_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class AudioServiceHelper {
}
}

if (!shuffle) {
// Give the audio service our next initial index so that playback starts
// at that index. We don't do this if shuffling because it causes the
// queue to always start at the start (although you could argue that we
// still should if initialIndex is not 0, but that doesn't happen
// anywhere in this app so oh well).
_audioHandler.setNextInitialIndex(initialIndex);
}
// if (!shuffle) {
// // Give the audio service our next initial index so that playback starts
// // at that index. We don't do this if shuffling because it causes the
// // queue to always start at the start (although you could argue that we
// // still should if initialIndex is not 0, but that doesn't happen
// // anywhere in this app so oh well).
_audioHandler.setNextInitialIndex(initialIndex);
// }

await _audioHandler.updateQueue(queue);

Expand Down
1 change: 0 additions & 1 deletion lib/services/music_player_background_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler {
try {
switch (shuffleMode) {
case AudioServiceShuffleMode.all:
await _player.shuffle();
await _player.setShuffleModeEnabled(true);
shuffleNextQueue = true;
break;
Expand Down