You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
import 'package:deep_voice/core/utils/logger.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:music_service/music_service.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
//音乐播放管理
|
|
class MusicManager extends GetxService {
|
|
static MusicManager get to => Get.find<MusicManager>();
|
|
|
|
// 音乐服务实例
|
|
final MusicService _musicService = MusicService();
|
|
|
|
/// 初始化
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
requestNotificationPermission();
|
|
Logger.info('初始化权限请求');
|
|
}
|
|
|
|
Future<void> requestNotificationPermission() async {
|
|
if (await Permission.notification.isDenied) {
|
|
await Permission.notification.request();
|
|
}
|
|
}
|
|
|
|
/// 释放资源
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
}
|
|
|
|
//播放
|
|
Future<void> play(Map<String, String> song) async {
|
|
await _musicService.playMusic(song);
|
|
}
|
|
|
|
//暂停
|
|
Future<void> pause() async {
|
|
await _musicService.pauseMusic();
|
|
}
|
|
|
|
//继续
|
|
Future<void> resume() async {
|
|
await _musicService.resumeMusic();
|
|
}
|
|
|
|
//状态
|
|
Future<Map<String, dynamic>> getStatus() async {
|
|
return await _musicService.getStatus();
|
|
}
|
|
}
|
|
|