diff --git a/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java b/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java index 7e7fe40..a9db645 100644 --- a/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java +++ b/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java @@ -695,6 +695,10 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud if (processingState == ProcessingState.loading) { abortExistingConnection(); } + if (playResult != null) { + playResult.success(new HashMap()); + playResult = null; + } mediaSources.clear(); mediaSource = null; if (player != null) { diff --git a/just_audio/example/pubspec.lock b/just_audio/example/pubspec.lock index ff8425b..6a0b8b5 100644 --- a/just_audio/example/pubspec.lock +++ b/just_audio/example/pubspec.lock @@ -134,7 +134,7 @@ packages: name: just_audio_web url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.1" matcher: dependency: transitive description: diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index ac065db..7bd8f3b 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -687,12 +687,16 @@ class AudioPlayer { _playCompleter = Completer(); final audioSession = await AudioSession.instance; if (await audioSession.setActive(true)) { - final shouldActivate = _audioSource != null; - if (shouldActivate) { + // TODO: rewrite this to more cleanly handle simultaneous load/play + // requests which each may result in platform play requests. + final requireActive = _audioSource != null; + if (requireActive) { if (_active) { // If the native platform is already active, send it a play request. - await (await _platform).play(PlayRequest()); - _playCompleter.complete(); + // NOTE: If a load() request happens simultaneously, this may result + // in two play requests being sent. The platform implementation should + // ignore the second play request since it is already playing. + _sendPlayRequest(await _platform); } else { // If the native platform wasn't already active, activating it will // implicitly restore the playing state and send a play request. @@ -702,9 +706,8 @@ class AudioPlayer { } else { // Revert if we fail to activate the audio session. _playingSubject.add(false); - _playCompleter.complete(); } - await _playCompleter.future; + await _playCompleter?.future; _playCompleter = null; } @@ -727,6 +730,13 @@ class AudioPlayer { await (await _platform).pause(PauseRequest()); } + Future _sendPlayRequest(AudioPlayerPlatform platform) async { + await platform.play(PlayRequest()); + if (_playCompleter?.isCompleted == false) { + _playCompleter.complete(); + } + } + /// Stops playing audio and releases decoders and other native platform /// resources needed to play audio. The current audio source state will be /// retained and playback can be resumed at a later point in time. @@ -981,7 +991,7 @@ class AudioPlayer { ? ShuffleModeMessage.all : ShuffleModeMessage.none)); if (playing) { - platform.play(PlayRequest()).then((_) => _playCompleter?.complete()); + _sendPlayRequest(platform); } } if (audioSource != null) { @@ -2081,8 +2091,6 @@ class _IdleAudioPlayer extends AudioPlayerPlatform { @override Future dispose(DisposeRequest request) async { - await _sequenceSubscription.cancel(); - await _eventSubject.close(); return DisposeResponse(); } diff --git a/just_audio/pubspec.lock b/just_audio/pubspec.lock index adda672..7e7b31c 100644 --- a/just_audio/pubspec.lock +++ b/just_audio/pubspec.lock @@ -204,7 +204,7 @@ packages: name: just_audio_web url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.1" logging: dependency: transitive description: diff --git a/just_audio/pubspec.yaml b/just_audio/pubspec.yaml index 0d44840..4e30e2f 100644 --- a/just_audio/pubspec.yaml +++ b/just_audio/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: just_audio_platform_interface: ^2.0.0 - just_audio_web: ^0.2.0 + just_audio_web: ^0.2.1 audio_session: ^0.0.9 rxdart: ">= 0.24.1 < 0.26.0" path: ^1.6.4