Cancel event subscription before disposing platform.

This commit is contained in:
Ryan Heise 2021-01-05 13:59:53 +11:00
parent 2cb1c04dfe
commit baa73045f0
1 changed files with 1 additions and 1 deletions

View File

@ -921,6 +921,7 @@ class AudioPlayer {
final audioSource = _audioSource;
final durationCompleter = Completer<Duration>();
_platform = Future<AudioPlayerPlatform>(() async {
_playbackEventSubscription?.cancel();
if (oldPlatformFuture != null) {
final oldPlatform = await oldPlatformFuture;
if (oldPlatform != _idlePlatform) {
@ -933,7 +934,6 @@ class AudioPlayer {
? await (_nativePlatform =
JustAudioPlatform.instance.init(InitRequest(id: _id)))
: _idlePlatform;
_playbackEventSubscription?.cancel();
_playbackEventSubscription =
platform.playbackEventMessageStream.listen((message) {
var duration = message.duration;