Skip to content

Commit

Permalink
Fix: Exception when calling insert() or removeAt() on ConcatenatingAu…
Browse files Browse the repository at this point in the history
…dioSource due to shuffleOrder not being updated
  • Loading branch information
jonmarkhall authored Apr 4, 2024
1 parent 6952be5 commit 0e48668
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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

0 comments on commit 0e48668

Please sign in to comment.