Skip to content

Commit

Permalink
Fix bug restoring speed after load.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jan 21, 2022
1 parent 2878524 commit b2c5d05
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion just_audio_web/lib/just_audio_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ abstract class JustAudioPlayer extends AudioPlayerPlatform {
ProcessingStateMessage _processingState = ProcessingStateMessage.idle;
bool _playing = false;
int? _index;
double _speed = 1.0;

/// Creates a platform player with the given [id].
JustAudioPlayer({required String id}) : super(id);
Expand Down Expand Up @@ -121,6 +122,7 @@ class Html5AudioPlayer extends JustAudioPlayer {
transition(ProcessingStateMessage.buffering);
});
_audioElement.addEventListener('canplaythrough', (event) {
_audioElement.playbackRate = _speed;
transition(ProcessingStateMessage.ready);
});
_audioElement.addEventListener('progress', (event) {
Expand Down Expand Up @@ -226,6 +228,7 @@ class Html5AudioPlayer extends JustAudioPlayer {
if (src != _audioElement.src) {
_durationCompleter = Completer<dynamic>();
_audioElement.src = src;
_audioElement.playbackRate = _speed;
_audioElement.preload = 'auto';
_audioElement.load();
if (initialPosition != null) {
Expand Down Expand Up @@ -275,7 +278,7 @@ class Html5AudioPlayer extends JustAudioPlayer {

@override
Future<SetSpeedResponse> setSpeed(SetSpeedRequest request) async {
_audioElement.playbackRate = request.speed;
_audioElement.playbackRate = _speed = request.speed;
return SetSpeedResponse();
}

Expand Down

0 comments on commit b2c5d05

Please sign in to comment.