From 8559bb319fe07835574fdb6e631c9be3592cbcc9 Mon Sep 17 00:00:00 2001 From: orz12 Date: Mon, 29 Jul 2024 19:33:38 +0800 Subject: [PATCH] listen devicesChangedEventStream, revert pause --- lib/services/audio_session.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/services/audio_session.dart b/lib/services/audio_session.dart index b404e72f0..da738a7d9 100644 --- a/lib/services/audio_session.dart +++ b/lib/services/audio_session.dart @@ -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 { @@ -19,8 +20,13 @@ class AudioSessionHandler { Future 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) { @@ -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; }