From a7aa51f9c3494664a4cb49478510483b062b1756 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Wed, 1 Sep 2021 01:52:04 +1000 Subject: [PATCH] Fix bug loading audio after concat insert/delete. --- just_audio_web/lib/just_audio_web.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/just_audio_web/lib/just_audio_web.dart b/just_audio_web/lib/just_audio_web.dart index 9a34111f6..a60001758 100644 --- a/just_audio_web/lib/just_audio_web.dart +++ b/just_audio_web/lib/just_audio_web.dart @@ -339,12 +339,14 @@ class Html5AudioPlayer extends JustAudioPlayer { @override Future 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(); } @@ -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