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

[just_audio_background] Fix: Shuffle order out of sync after inserting/removing item from ConcatenatingAudioSource #1221

Open
wants to merge 1 commit into
base: minor
Choose a base branch
from
Open
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
26 changes: 14 additions & 12 deletions just_audio/lib/just_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2543,12 +2543,13 @@ class ConcatenatingAudioSource extends AudioSource {
if (_player != null) {
_player!._broadcastSequence();
await audioSource._setup(_player!);
await (await _player!._platform).concatenatingInsertAll(
ConcatenatingInsertAllRequest(
id: _id,
index: index,
children: [audioSource._toMessage()],
shuffleOrder: List.of(_shuffleOrder.indices)));
ConcatenatingInsertAllRequest request = ConcatenatingInsertAllRequest(
id: _id,
index: index,
children: [audioSource._toMessage()],
shuffleOrder: List.of(_shuffleOrder.indices)
);
await (await _player!._platform).concatenatingInsertAll(request);
}
}

Expand Down Expand Up @@ -2596,12 +2597,13 @@ class ConcatenatingAudioSource extends AudioSource {
_shuffleOrder.removeRange(index, index + 1);
if (_player != null) {
_player!._broadcastSequence();
await (await _player!._platform).concatenatingRemoveRange(
ConcatenatingRemoveRangeRequest(
id: _id,
startIndex: index,
endIndex: index + 1,
shuffleOrder: List.of(_shuffleOrder.indices)));
ConcatenatingRemoveRangeRequest request = ConcatenatingRemoveRangeRequest(
id: _id,
startIndex: index,
endIndex: index + 1,
shuffleOrder: List.of(_shuffleOrder.indices)
);
await (await _player!._platform).concatenatingRemoveRange(request);
}
}

Expand Down
4 changes: 4 additions & 0 deletions just_audio_background/lib/just_audio_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ class _PlayerAudioHandler extends BaseAudioHandler
ConcatenatingInsertAllRequest request) async {
final cat = _source!.findCat(request.id)!;
cat.children.insertAll(request.index, request.children);
cat.shuffleOrder.clear();
cat.shuffleOrder.addAll(request.shuffleOrder);
_updateShuffleIndices();
_broadcastStateIfActive();
_updateQueue();
Expand All @@ -521,6 +523,8 @@ class _PlayerAudioHandler extends BaseAudioHandler
ConcatenatingRemoveRangeRequest request) async {
final cat = _source!.findCat(request.id)!;
cat.children.removeRange(request.startIndex, request.endIndex);
cat.shuffleOrder.clear();
cat.shuffleOrder.addAll(request.shuffleOrder);
_updateShuffleIndices();
_broadcastStateIfActive();
_updateQueue();
Expand Down