Fix bug on second setAudioSource call.
This commit is contained in:
parent
fc1a6b37e9
commit
8d645bb75f
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue