From 9dcc85d47965aee1b205f2618c29a8752d270498 Mon Sep 17 00:00:00 2001 From: eon-ic Date: Thu, 30 Jul 2026 17:43:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(audio=5Fservice):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=AA=E5=88=ABAndroid=E7=9A=84=E9=80=9A=E7=9F=A5=E6=A0=8F?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 1 + lib/core/services/audio_handler.dart | 11 +++-- lib/main.dart | 9 +++- linux/CMakeLists.txt | 1 + pubspec.lock | 62 +++++++++++++++++++++--- pubspec.yaml | 6 +-- 6 files changed, 75 insertions(+), 15 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b6425b4..d31468b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ xmlns:tools="http://schemas.android.com/tools"> + diff --git a/lib/core/services/audio_handler.dart b/lib/core/services/audio_handler.dart index 3ac3b7d..fc72538 100644 --- a/lib/core/services/audio_handler.dart +++ b/lib/core/services/audio_handler.dart @@ -23,9 +23,6 @@ class BusicAudioHandler extends BaseAudioHandler with SeekHandler { Future Function()? onSkipToPrevious; Future Function(Duration position)? onSeek; Future Function()? onStop; - - BusicAudioHandler(); - @override Future play() async { await onPlay?.call(); @@ -83,7 +80,13 @@ class BusicAudioHandler extends BaseAudioHandler with SeekHandler { PlaybackState( controls: [ MediaControl.skipToPrevious, - playing ? MediaControl.pause : MediaControl.play, + MediaControl( + androidIcon: playing + ? 'drawable/audio_service_pause' + : 'drawable/audio_service_play_arrow', + label: 'PlayPause', + action: MediaAction.playPause, + ), MediaControl.skipToNext, ], systemActions: const { diff --git a/lib/main.dart b/lib/main.dart index 525f49a..4ab640f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:audio_service/audio_service.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:media_kit/media_kit.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'app.dart'; import 'core/api/bili_dio.dart'; @@ -54,7 +55,13 @@ Future main() async { androidStopForegroundOnPause: true, ), ); - + // Android: Get Permission + if (PlatformUtils.isAndroid) { + var notificationStatus = await Permission.notification.status; + if (!notificationStatus.isGranted) { + notificationStatus = await Permission.notification.request(); + } + } // Desktop-specific: initialize window manager and system tray if (PlatformUtils.isDesktop) { await WindowService.initialize(); diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 30c76ae..a978366 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -43,6 +43,7 @@ function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_options(${TARGET} PRIVATE -Wno-error=deprecated-declarations) target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() diff --git a/pubspec.lock b/pubspec.lock index 16cf104..59712fd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -282,13 +282,13 @@ packages: source: hosted version: "3.1.8" dbus: - dependency: transitive + dependency: "direct main" description: name: dbus - sha256: d0c98dcd4f5169878b6cf8f6e0a52403a9dff371a3e2f019697accbf6f44a270 + sha256: "0ce9b0a839e6dee59a37a623d2fc26a35bbbe6404213e419b0d6411023d62645" url: "https://pub.dev" source: hosted - version: "0.7.12" + version: "0.7.14" dio: dependency: "direct main" description: @@ -853,14 +853,62 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + sha256: fe54465bcc62a4564c6e4db337bbaded6c0c0fa6e10487414436d163114784f6 + url: "https://pub.dev" + source: hosted + version: "12.0.3" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + sha256: "1e3bc410ca1bf84662104b100eb126e066cb55791b7451307f9708d4007350e6" + url: "https://pub.dev" + source: hosted + version: "13.0.1" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + sha256: "79dfa1df734798aa3cfdad166d3a3698c206d8813de13516ea1071b5d7e2f420" + url: "https://pub.dev" + source: hosted + version: "9.4.10" + permission_handler_html: + dependency: transitive + description: + name: permission_handler_html + sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24" + url: "https://pub.dev" + source: hosted + version: "0.1.3+5" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + sha256: eb99b295153abce5d683cac8c02e22faab63e50679b937fa1bf67d58bb282878 + url: "https://pub.dev" + source: hosted + version: "4.3.0" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" + url: "https://pub.dev" + source: hosted + version: "0.2.1" petitparser: dependency: transitive description: name: petitparser - sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646" + sha256: "91bd59303e9f769f108f8df05e371341b15d59e995e6806aefab827b58336675" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "7.0.2" platform: dependency: transitive description: @@ -1478,10 +1526,10 @@ packages: dependency: transitive description: name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025" url: "https://pub.dev" source: hosted - version: "6.5.0" + version: "6.6.1" yaml: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0333e57..62c0482 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,8 +4,8 @@ publish_to: "none" version: 0.4.3+18 environment: - sdk: '>=3.12.2 <4.0.0' - flutter: '>=3.44.6' + sdk: ">=3.12.2 <4.0.0" + flutter: ">=3.44.6" dependencies: flutter: @@ -68,7 +68,7 @@ dependencies: file_picker: ^10.3.10 audio_service: ^0.18.18 tray_manager: ^0.5.2 - + permission_handler: ^12.0.3 # App Update yaml: ^3.1.2 archive: ^4.0.2