Skip to content

Commit

Permalink
Fix shuffle always starts on first song(issues:jmshrv#61) and remove …
Browse files Browse the repository at this point in the history
…redundant code
  • Loading branch information
yuruxuan committed Apr 30, 2023
1 parent ec3be0a commit 4efad6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
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

0 comments on commit 4efad6e

Please sign in to comment.