Skip to content

Commit

Permalink
Fix bug with play before load.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Dec 22, 2020
1 parent c19ac28 commit edd2fd5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions just_audio_web/lib/just_audio_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,13 @@ class Html5AudioPlayer extends JustAudioPlayer {

List<int> get order {
final sequence = _audioSourcePlayer.sequence;
List<int> order = List<int>(sequence.length);
if (_shuffleModeEnabled) {
order = _audioSourcePlayer.shuffleIndices;
} else {
for (var i = 0; i < order.length; i++) {
order[i] = i;
}
}
return order;
return _shuffleModeEnabled
? _audioSourcePlayer.shuffleIndices
: List.generate(sequence.length, (i) => i);
}

List<int> getInv(List<int> order) {
List<int> orderInv = List<int>(order.length);
final orderInv = List<int>.filled(order.length, 0);
for (var i = 0; i < order.length; i++) {
orderInv[order[i]] = i;
}
Expand Down Expand Up @@ -222,19 +216,21 @@ class Html5AudioPlayer extends JustAudioPlayer {

@override
Future<PlayResponse> play(PlayRequest request) async {
if (_playing) return PlayResponse();
_playing = true;
await _play();
return PlayResponse();
}

Future<void> _play() async {
_playing = true;
await _currentAudioSourcePlayer.play();
await _currentAudioSourcePlayer?.play();
}

@override
Future<PauseResponse> pause(PauseRequest request) async {
if (!_playing) return PauseResponse();
_playing = false;
_currentAudioSourcePlayer.pause();
_currentAudioSourcePlayer?.pause();
return PauseResponse();
}

Expand Down

0 comments on commit edd2fd5

Please sign in to comment.