From 0e48668db2c4b686b919b9670e0604acfb24e31a Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Thu, 4 Apr 2024 14:10:16 -0700 Subject: [PATCH] Fix: Exception when calling insert() or removeAt() on ConcatenatingAudioSource due to shuffleOrder not being updated --- just_audio/lib/just_audio.dart | 26 ++++++++++--------- .../lib/just_audio_background.dart | 4 +++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 759835e82..0c3d30e90 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -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); } } @@ -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); } } diff --git a/just_audio_background/lib/just_audio_background.dart b/just_audio_background/lib/just_audio_background.dart index 17caf5897..284ce3c17 100644 --- a/just_audio_background/lib/just_audio_background.dart +++ b/just_audio_background/lib/just_audio_background.dart @@ -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(); @@ -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();