From 0e48668db2c4b686b919b9670e0604acfb24e31a Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Thu, 4 Apr 2024 14:10:16 -0700 Subject: [PATCH 1/2] 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(); From f75582cbdf9922735104d13fb6a8784a409d1f68 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Sun, 15 Dec 2024 18:57:43 +1100 Subject: [PATCH 2/2] Fix shuffleOrder in just_audio_background for ConcatenatingMoveRequest. --- just_audio/lib/just_audio.dart | 26 +++++++++---------- just_audio_background/CHANGELOG.md | 4 +++ .../lib/just_audio_background.dart | 10 ++++--- just_audio_background/pubspec.yaml | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index e20a88433..057028a6e 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -2598,13 +2598,12 @@ class ConcatenatingAudioSource extends AudioSource { if (_player != null) { _player!._broadcastSequence(); await audioSource._setup(_player!); - ConcatenatingInsertAllRequest request = ConcatenatingInsertAllRequest( - id: _id, - index: index, - children: [audioSource._toMessage()], - shuffleOrder: List.of(_shuffleOrder.indices) - ); - await (await _player!._platform).concatenatingInsertAll(request); + await (await _player!._platform).concatenatingInsertAll( + ConcatenatingInsertAllRequest( + id: _id, + index: index, + children: [audioSource._toMessage()], + shuffleOrder: List.of(_shuffleOrder.indices))); } } @@ -2652,13 +2651,12 @@ class ConcatenatingAudioSource extends AudioSource { _shuffleOrder.removeRange(index, index + 1); if (_player != null) { _player!._broadcastSequence(); - ConcatenatingRemoveRangeRequest request = ConcatenatingRemoveRangeRequest( - id: _id, - startIndex: index, - endIndex: index + 1, - shuffleOrder: List.of(_shuffleOrder.indices) - ); - await (await _player!._platform).concatenatingRemoveRange(request); + await (await _player!._platform).concatenatingRemoveRange( + ConcatenatingRemoveRangeRequest( + id: _id, + startIndex: index, + endIndex: index + 1, + shuffleOrder: List.of(_shuffleOrder.indices))); } } diff --git a/just_audio_background/CHANGELOG.md b/just_audio_background/CHANGELOG.md index 5e945226c..ac0472ff8 100644 --- a/just_audio_background/CHANGELOG.md +++ b/just_audio_background/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.1-beta.14 + +* Fix shuffleOrder when mutating ConcatenatingAudioSource (@jonmarkhall). + ## 0.0.1-beta.13 * Support rxdart 0.28.x. diff --git a/just_audio_background/lib/just_audio_background.dart b/just_audio_background/lib/just_audio_background.dart index 7a2f26499..4be09ce05 100644 --- a/just_audio_background/lib/just_audio_background.dart +++ b/just_audio_background/lib/just_audio_background.dart @@ -523,8 +523,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); + cat.shuffleOrder + .replaceRange(0, cat.shuffleOrder.length, request.shuffleOrder); _updateShuffleIndices(); _broadcastStateIfActive(); _updateQueue(); @@ -535,8 +535,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); + cat.shuffleOrder + .replaceRange(0, cat.shuffleOrder.length, request.shuffleOrder); _updateShuffleIndices(); _broadcastStateIfActive(); _updateQueue(); @@ -548,6 +548,8 @@ class _PlayerAudioHandler extends BaseAudioHandler final cat = _source!.findCat(request.id)!; cat.children .insert(request.newIndex, cat.children.removeAt(request.currentIndex)); + cat.shuffleOrder + .replaceRange(0, cat.shuffleOrder.length, request.shuffleOrder); _updateShuffleIndices(); _broadcastStateIfActive(); _updateQueue(); diff --git a/just_audio_background/pubspec.yaml b/just_audio_background/pubspec.yaml index a3247ec47..969fdf441 100644 --- a/just_audio_background/pubspec.yaml +++ b/just_audio_background/pubspec.yaml @@ -1,7 +1,7 @@ name: just_audio_background description: An add-on for just_audio that supports background playback and media notifications. homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio_background -version: 0.0.1-beta.13 +version: 0.0.1-beta.14 topics: - audio - sound