Skip to content

Commit

Permalink
Fix bug loading audio after concat insert/delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Aug 31, 2021
1 parent 529cf6a commit a7aa51f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions just_audio_web/lib/just_audio_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,14 @@ class Html5AudioPlayer extends JustAudioPlayer {
@override
Future<ConcatenatingInsertAllResponse> concatenatingInsertAll(
ConcatenatingInsertAllRequest request) async {
final wasNotEmpty = _audioSourcePlayer?.sequence.isNotEmpty ?? false;
_concatenating(request.id)!.setShuffleOrder(request.shuffleOrder);
_concatenating(request.id)!
.insertAll(request.index, getAudioSources(request.children));
if (_index != null && request.index <= _index!) {
if (_index != null && wasNotEmpty && request.index <= _index!) {
_index = _index! + request.children.length;
}
await _currentAudioSourcePlayer!.load();
broadcastPlaybackEvent();
return ConcatenatingInsertAllResponse();
}
Expand Down Expand Up @@ -372,9 +374,11 @@ class Html5AudioPlayer extends JustAudioPlayer {
_index = request.startIndex;
}
// Resume playback at the new item (if it exists)
if (_playing && _currentAudioSourcePlayer != null) {
if (_currentAudioSourcePlayer != null) {
await _currentAudioSourcePlayer!.load();
_currentAudioSourcePlayer!.play();
if (_playing) {
_currentAudioSourcePlayer!.play();
}
}
} else if (request.endIndex <= _index!) {
// Reflect that the current item has shifted its position
Expand Down

0 comments on commit a7aa51f

Please sign in to comment.