Skip to content

Commit

Permalink
listen devicesChangedEventStream, revert pause
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jul 29, 2024
1 parent e0a5fc3 commit 8559bb3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/services/audio_session.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:audio_session/audio_session.dart';
import 'package:PiliPalaX/plugin/pl_player/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class AudioSessionHandler {
Expand All @@ -19,8 +20,13 @@ class AudioSessionHandler {
Future<void> initSession() async {
session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration.music());

session.interruptionEventStream.listen((AudioInterruptionEvent event) async {
session.devicesChangedEventStream.listen((AudioDevicesChangedEvent event) =>
SmartDialog.showNotify(
alignment: Alignment.centerLeft,
msg: '设备变化, ${event.devicesAdded}, ${event.devicesRemoved}',
notifyType: NotifyType.alert));
session.interruptionEventStream
.listen((AudioInterruptionEvent event) async {
final playerStatus = PlPlayerController.getPlayerStatusIfExists();
// final player = PlPlayerController.getInstance();
if (event.begin) {
Expand All @@ -36,7 +42,7 @@ class AudioSessionHandler {
case AudioInterruptionType.unknown:
SmartDialog.showNotify(
msg: '音频播放被中断, ${event.type}', notifyType: NotifyType.error);
// PlPlayerController.pauseIfExists(isInterrupt: true);
PlPlayerController.pauseIfExists(isInterrupt: true);
_playInterrupted = true;
break;
}
Expand Down

0 comments on commit 8559bb3

Please sign in to comment.