Skip to content

Commit

Permalink
fix: 尝试修复焦点恢复时错误播放的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 4, 2024
1 parent 173abd8 commit 8b387e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/services/audio_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -47,7 +51,10 @@ class AudioSessionHandler {

// 耳机拔出暂停
session.becomingNoisyEventStream.listen((_) {
PlPlayerController.getInstance().pause();
final player = PlPlayerController.getInstance();
if (player.playerStatus == PlayerStatus.playing) {
player.pause();
}
});
}
}

0 comments on commit 8b387e9

Please sign in to comment.