diff --git a/lib/services/audio_session.dart b/lib/services/audio_session.dart index 98707652a..57c42e053 100644 --- a/lib/services/audio_session.dart +++ b/lib/services/audio_session.dart @@ -20,11 +20,15 @@ class AudioSessionHandler { session.interruptionEventStream.listen((event) { final player = PlPlayerController.getInstance(); if (event.begin) { + if (player.playerStatus != PlayerStatus.playing) return; switch (event.type) { case AudioInterruptionType.duck: player.setVolume(player.volume.value * 0.5); break; case AudioInterruptionType.pause: + player.pause(isInterrupt: true); + _playInterrupted = true; + break; case AudioInterruptionType.unknown: player.pause(isInterrupt: true); _playInterrupted = true; @@ -36,7 +40,7 @@ class AudioSessionHandler { player.setVolume(player.volume.value * 2); break; case AudioInterruptionType.pause: - if (_playInterrupted) PlPlayerController.getInstance().play(); + if (_playInterrupted) player.play(); break; case AudioInterruptionType.unknown: break; @@ -47,7 +51,10 @@ class AudioSessionHandler { // 耳机拔出暂停 session.becomingNoisyEventStream.listen((_) { - PlPlayerController.getInstance().pause(); + final player = PlPlayerController.getInstance(); + if (player.playerStatus == PlayerStatus.playing) { + player.pause(); + } }); } }