From 0a5dea0535f272f5b6ddd87c5ae76abb70a4525f Mon Sep 17 00:00:00 2001 From: Riri Date: Wed, 25 Oct 2023 16:27:14 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 22 +++- .../drawable-xxhdpi-v26/ic_stat_replay_10.png | Bin 0 -> 2454 bytes .../res/drawable-xxhdpi/ic_stat_replay_10.png | Bin 0 -> 2454 bytes .../ic_stat_forward_10.png | Bin 0 -> 2882 bytes .../ic_stat_replay_10.png | Bin 0 -> 2933 bytes .../drawable-xxxhdpi/ic_stat_forward_10.png | Bin 0 -> 2882 bytes .../drawable-xxxhdpi/ic_stat_replay_10.png | Bin 0 -> 2933 bytes ios/Runner/Info.plist | 4 + lib/main.dart | 2 + lib/pages/video/detail/introduction/view.dart | 3 + lib/plugin/pl_player/controller.dart | 14 +++ lib/services/audio_handler.dart | 116 ++++++++++++++++++ lib/services/service_locator.dart | 8 ++ macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.lock | 76 +++++++++--- pubspec.yaml | 7 +- 16 files changed, 235 insertions(+), 21 deletions(-) create mode 100644 android/app/src/main/res/drawable-xxhdpi-v26/ic_stat_replay_10.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/ic_stat_replay_10.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi-v26/ic_stat_forward_10.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi-v26/ic_stat_replay_10.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/ic_stat_forward_10.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/ic_stat_replay_10.png create mode 100644 lib/services/audio_handler.dart create mode 100644 lib/services/service_locator.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index dc980d0f1..ebbfa2f1c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -45,7 +45,7 @@ android:fullBackupContent="false" tools:replace="android:allowBackup"> + + + + + + + + + + + + + diff --git a/android/app/src/main/res/raw/keep.xml b/android/app/src/main/res/raw/keep.xml new file mode 100644 index 000000000..0a4bfd53f --- /dev/null +++ b/android/app/src/main/res/raw/keep.xml @@ -0,0 +1,3 @@ + + \ No newline at end of file From 2348c140084600cbc2bf909027f6736f5d89760b Mon Sep 17 00:00:00 2001 From: Riri Date: Sat, 28 Oct 2023 14:52:29 +0800 Subject: [PATCH 10/10] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=B8=8D?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=90=8E=E5=8F=B0=E6=92=AD=E6=94=BE=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=9F=B3=E9=A2=91=E6=89=93=E6=96=AD=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9C=89=E9=80=9A=E7=9F=A5=E6=98=AF=E5=87=8F=E5=B0=8F?= =?UTF-8?q?=E9=9F=B3=E9=87=8F=E9=80=9A=E7=9F=A5=E7=BB=93=E6=9D=9F=E6=97=B6?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin/pl_player/controller.dart | 1 + lib/services/audio_handler.dart | 47 ------------------------ lib/services/audio_session.dart | 53 ++++++++++++++++++++++++++++ lib/services/service_locator.dart | 3 ++ 4 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 lib/services/audio_session.dart diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index e4f1b3d32..ec8627381 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -646,6 +646,7 @@ class PlPlayerController { playerStatus.status.value = PlayerStatus.playing; // screenManager.setOverlays(false); + audioSessionHandler.setActive(true); } /// 暂停播放 diff --git a/lib/services/audio_handler.dart b/lib/services/audio_handler.dart index 67b8cb892..61b32b96b 100644 --- a/lib/services/audio_handler.dart +++ b/lib/services/audio_handler.dart @@ -5,7 +5,6 @@ import 'package:pilipala/models/video_detail_res.dart'; import 'package:get/get.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/utils/storage.dart'; -import 'package:audio_session/audio_session.dart'; Future initAudioService() async { return await AudioService.init( @@ -27,49 +26,9 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { static final List _item = []; Box setting = GStrorage.setting; bool enableBackgroundPlay = false; - late AudioSession session; - bool _playInterrupted = false; // 暂时无用 VideoPlayerServiceHandler() { revalidateSetting(); - initSession(); - } - - Future initSession() async { - session = await AudioSession.instance; - session.configure(const AudioSessionConfiguration.speech()); - - session.interruptionEventStream.listen((event) { - if (event.begin) { - switch (event.type) { - case AudioInterruptionType.duck: - // duck or pause - // break; - case AudioInterruptionType.pause: - case AudioInterruptionType.unknown: - pause(); - _playInterrupted = true; - break; - } - } else { - switch (event.type) { - case AudioInterruptionType.duck: - // unduck - // break; - case AudioInterruptionType.pause: - if (_playInterrupted) play(); - break; - case AudioInterruptionType.unknown: - break; - } - _playInterrupted = false; - } - }); - - // 耳机拔出暂停 - session.becomingNoisyEventStream.listen((_) { - pause(); - }); } revalidateSetting() { @@ -105,12 +64,6 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { final AudioProcessingState processingState; final playing = status == PlayerStatus.playing; - if (playing) { - _playInterrupted = false; - session.setActive(true); - } else { - session.setActive(false); - } if (status == PlayerStatus.completed) { processingState = AudioProcessingState.completed; } else if (isBuffering) { diff --git a/lib/services/audio_session.dart b/lib/services/audio_session.dart new file mode 100644 index 000000000..3dd9db456 --- /dev/null +++ b/lib/services/audio_session.dart @@ -0,0 +1,53 @@ +import 'package:audio_session/audio_session.dart'; +import 'package:pilipala/plugin/pl_player/index.dart'; + +class AudioSessionHandler { + late AudioSession session; + bool _playInterrupted = false; + + setActive(bool active) { + session.setActive(active); + } + + AudioSessionHandler() { + initSession(); + } + + Future initSession() async { + session = await AudioSession.instance; + session.configure(const AudioSessionConfiguration.music()); + + session.interruptionEventStream.listen((event) { + final player = PlPlayerController.getInstance(); + if (event.begin) { + switch (event.type) { + case AudioInterruptionType.duck: + player.setVolume(player.volume.value * 0.5); + break; + case AudioInterruptionType.pause: + case AudioInterruptionType.unknown: + player.pause(); + _playInterrupted = true; + break; + } + } else { + switch (event.type) { + case AudioInterruptionType.duck: + player.setVolume(player.volume.value * 2); + break; + case AudioInterruptionType.pause: + if (_playInterrupted) PlPlayerController.getInstance().play(); + break; + case AudioInterruptionType.unknown: + break; + } + _playInterrupted = false; + } + }); + + // 耳机拔出暂停 + session.becomingNoisyEventStream.listen((_) { + PlPlayerController.getInstance().pause(); + }); + } +} diff --git a/lib/services/service_locator.dart b/lib/services/service_locator.dart index 8b9e5af06..e4497660d 100644 --- a/lib/services/service_locator.dart +++ b/lib/services/service_locator.dart @@ -1,8 +1,11 @@ import 'audio_handler.dart'; +import 'audio_session.dart'; late VideoPlayerServiceHandler videoPlayerServiceHandler; +late AudioSessionHandler audioSessionHandler; Future setupServiceLocator() async { final audio = await initAudioService(); videoPlayerServiceHandler = audio; + audioSessionHandler = AudioSessionHandler(); }