Process play/pause state transitions in a consistent order.

This commit is contained in:
Ryan Heise 2020-12-23 17:54:24 +11:00
parent f7532f944a
commit 845a1e4606
1 changed files with 5 additions and 1 deletions

View File

@ -682,6 +682,10 @@ class AudioPlayer {
// Broadcast to clients immediately, but revert to false if we fail to // Broadcast to clients immediately, but revert to false if we fail to
// activate the audio session. This allows setAudioSource to be aware of a // activate the audio session. This allows setAudioSource to be aware of a
// prior play request. // prior play request.
_playbackEvent = _playbackEvent.copyWith(
updatePosition: position,
updateTime: DateTime.now(),
);
_playingSubject.add(true); _playingSubject.add(true);
final playCompleter = Completer(); final playCompleter = Completer();
final audioSession = await AudioSession.instance; final audioSession = await AudioSession.instance;
@ -721,8 +725,8 @@ class AudioPlayer {
updatePosition: position, updatePosition: position,
updateTime: DateTime.now(), updateTime: DateTime.now(),
); );
_playbackEventSubject.add(_playbackEvent);
_playingSubject.add(false); _playingSubject.add(false);
_playbackEventSubject.add(_playbackEvent);
// TODO: perhaps modify platform side to ensure new state is broadcast // TODO: perhaps modify platform side to ensure new state is broadcast
// before this method returns. // before this method returns.
await (await _platform).pause(PauseRequest()); await (await _platform).pause(PauseRequest());