|
|
|
@ -2,22 +2,26 @@ import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import '../../../routes/app_routes.dart'; |
|
|
|
import '../controllers/agent_controller.dart'; |
|
|
|
import '../../../data/services/qq_musoc.dart'; |
|
|
|
import '../../../data/models/song_model.dart'; |
|
|
|
import 'circular_progress_button.dart'; |
|
|
|
|
|
|
|
/// 构建音乐项目 |
|
|
|
Widget buildQQMusicItem( |
|
|
|
BuildContext context, String id, String name, String singer, String image) { |
|
|
|
final controller = Get.find<AgentController>(); // 获取控制器 |
|
|
|
final qqMusicService = QqMusocService.to; // 使用QQ音乐全局服务 |
|
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark; |
|
|
|
Map<String, dynamic> song = { |
|
|
|
'id': id, |
|
|
|
'title': name, |
|
|
|
'artist': singer, |
|
|
|
'coverUrl': image, |
|
|
|
}; |
|
|
|
|
|
|
|
controller.musicStatus(); //刷新状态 |
|
|
|
// 创建SongModel对象 - 修复字段名 |
|
|
|
final song = SongModel( |
|
|
|
mid: id, |
|
|
|
name: name, |
|
|
|
artist: singer, // 修复:使用 artist 而不是 singer |
|
|
|
album: '', // 添加必需的 album 字段 |
|
|
|
duration: 0, // 默认时长,实际播放时会更新 |
|
|
|
albumPic: image, // 修复:使用 albumPic 而不是 pic |
|
|
|
); |
|
|
|
|
|
|
|
return Container( |
|
|
|
padding: EdgeInsets.all(14.w), |
|
|
|
decoration: BoxDecoration( |
|
|
|
@ -84,12 +88,16 @@ Widget buildQQMusicItem( |
|
|
|
), |
|
|
|
), |
|
|
|
Obx(() { |
|
|
|
final isThisPlaying = |
|
|
|
controller.isPlaying.value && controller.currentId.value == id; |
|
|
|
// 使用QQ音乐服务的全局状态 |
|
|
|
final isThisPlaying = qqMusicService.isPlaying.value && |
|
|
|
qqMusicService.currentSong.value?.mid == id; |
|
|
|
|
|
|
|
// 只有当前播放的歌曲才显示进度 |
|
|
|
// 计算播放进度 |
|
|
|
final currentProgress = |
|
|
|
isThisPlaying ? controller.progress.value : 0.0; |
|
|
|
isThisPlaying && qqMusicService.totalDuration.value > 0 |
|
|
|
? qqMusicService.currentPosition.value / |
|
|
|
qqMusicService.totalDuration.value |
|
|
|
: 0.0; |
|
|
|
|
|
|
|
return CircularProgressButton( |
|
|
|
isPlaying: isThisPlaying, |
|
|
|
@ -100,33 +108,43 @@ Widget buildQQMusicItem( |
|
|
|
strokeWidth: 2.0, |
|
|
|
onPlayPause: () async { |
|
|
|
try { |
|
|
|
if (controller.isPlaying.value) { |
|
|
|
if (controller.currentId.value == id) { |
|
|
|
if (qqMusicService.isPlaying.value) { |
|
|
|
if (qqMusicService.currentSong.value?.mid == id) { |
|
|
|
// 当前歌曲正在播放,暂停它 |
|
|
|
await controller.musicPause(); |
|
|
|
await qqMusicService.pauseMusic(); |
|
|
|
} else { |
|
|
|
// 其他歌曲正在播放,播放这首歌 |
|
|
|
await controller.musicPlay(song); |
|
|
|
await qqMusicService.playSongs( |
|
|
|
songMids: [id], |
|
|
|
index: 0, |
|
|
|
songList: [song], |
|
|
|
currentSongModel: song, |
|
|
|
); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (controller.currentId.value == id) { |
|
|
|
if (qqMusicService.currentSong.value?.mid == id) { |
|
|
|
// 当前歌曲已暂停,恢复播放 |
|
|
|
await controller.musicResume(); |
|
|
|
await qqMusicService.resumeMusic(); |
|
|
|
} else { |
|
|
|
// 播放新歌曲 |
|
|
|
await controller.musicPlay(song); |
|
|
|
await qqMusicService.playSongs( |
|
|
|
songMids: [id], |
|
|
|
index: 0, |
|
|
|
songList: [song], |
|
|
|
currentSongModel: song, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
// 静默处理错误,避免影响用户体验 |
|
|
|
print('播放控制失败: $e'); |
|
|
|
} |
|
|
|
}, |
|
|
|
onSeek: isThisPlaying |
|
|
|
? (seekProgress) { |
|
|
|
// 只有当前播放的歌曲才允许跳转 |
|
|
|
final targetPosition = |
|
|
|
(controller.duration.value * seekProgress).round(); |
|
|
|
controller.seekToPosition(targetPosition); |
|
|
|
// QQ音乐暂不支持拖拽进度,可以在这里添加相关逻辑 |
|
|
|
// 或者显示提示信息 |
|
|
|
print('QQ音乐暂不支持拖拽进度'); |
|
|
|
} |
|
|
|
: null, |
|
|
|
); |
|
|
|
@ -140,8 +158,20 @@ Widget buildQQMusicItem( |
|
|
|
Widget buildQQMusicContent( |
|
|
|
BuildContext context, List<Map<String, dynamic>> playlist) { |
|
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark; |
|
|
|
final controller = Get.find<AgentController>(); // 获取控制器 |
|
|
|
controller.updateCurrentPlaylistContext(playlist, controller.currentId.value); |
|
|
|
final qqMusicService = QqMusocService.to; // 使用QQ音乐全局服务 |
|
|
|
|
|
|
|
// 将播放列表转换为SongModel列表 - 修复字段名 |
|
|
|
final songList = playlist |
|
|
|
.map((item) => SongModel( |
|
|
|
mid: item["mid"] ?? "", |
|
|
|
name: item["name"] ?? "未知歌曲", |
|
|
|
artist: item["singer"] ?? "未知歌手", // 修复:使用 artist 而不是 singer |
|
|
|
album: '', // 添加必需的 album 字段 |
|
|
|
duration: 0, |
|
|
|
albumPic: item["pic"] ?? "", // 修复:使用 albumPic 而不是 pic |
|
|
|
)) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
return Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
@ -209,7 +239,7 @@ Widget buildQQMusicContent( |
|
|
|
child: TextButton( |
|
|
|
onPressed: () { |
|
|
|
// 跳转到完整歌单页面,传递完整的歌单数据 |
|
|
|
Get.toNamed(Routes.qqmusic, arguments: playlist); |
|
|
|
Get.toNamed(Routes.qqmusic, arguments: {"playlist": playlist}); |
|
|
|
}, |
|
|
|
style: TextButton.styleFrom( |
|
|
|
minimumSize: Size.zero, |
|
|
|
|