Fix bug on second setAudioSource call.

This commit is contained in:
Ryan Heise 2020-12-20 13:50:17 +11:00
parent fc1a6b37e9
commit 8d645bb75f
1 changed files with 13 additions and 8 deletions

View File

@ -546,7 +546,11 @@ class AudioPlayer {
currentIndex: initialIndex, updatePosition: initialPosition)); currentIndex: initialIndex, updatePosition: initialPosition));
_broadcastSequence(); _broadcastSequence();
// If the active platform existed, we should try to retain it. // If the active platform existed, we should try to retain it.
_setPlatformActive(false); try {
await _setPlatformActive(false);
} catch (e) {
print("Error deactivating previous platform: $e (ignoring)");
}
_audioSource = source; _audioSource = source;
_broadcastSequence(); _broadcastSequence();
Duration duration; Duration duration;
@ -885,15 +889,14 @@ class AudioPlayer {
? JustAudioPlatform.instance.init(InitRequest(id: _id)) ? JustAudioPlatform.instance.init(InitRequest(id: _id))
: Future.value(_idlePlatform); : Future.value(_idlePlatform);
_playbackEventSubscription?.cancel(); _playbackEventSubscription?.cancel();
if (oldPlatformFuture != null) {
oldPlatformFuture.then((platform) {
if (platform != _idlePlatform) {
_disposePlatform(platform);
}
});
}
final durationCompleter = Completer<Duration>(); final durationCompleter = Completer<Duration>();
_platform = Future<AudioPlayerPlatform>(() async { _platform = Future<AudioPlayerPlatform>(() async {
if (oldPlatformFuture != null) {
final oldPlatform = await oldPlatformFuture;
if (oldPlatform != _idlePlatform) {
await _disposePlatform(oldPlatform);
}
}
// During initialisation, we must only use this platform reference in case // During initialisation, we must only use this platform reference in case
// _platform is updated again during initialisation. // _platform is updated again during initialisation.
final platform = await newPlatform; final platform = await newPlatform;
@ -978,6 +981,8 @@ class AudioPlayer {
_audioSource = null; _audioSource = null;
durationCompleter.completeError(e, stackTrace); durationCompleter.completeError(e, stackTrace);
} }
} else {
durationCompleter.complete(null);
} }
return platform; return platform;