|
|
|
@ -5,7 +5,6 @@ import 'dart:io'; |
|
|
|
import 'package:amap_service/amap_service.dart'; |
|
|
|
import 'package:deep_voice/core/utils/upload_oss.dart'; |
|
|
|
import 'package:deep_voice/data/models/user_Info.dart'; |
|
|
|
import 'package:deep_voice/data/services/location_manager.dart'; |
|
|
|
import 'package:deep_voice/data/services/music_manager.dart'; |
|
|
|
import 'package:deep_voice/data/services/navigation_manager.dart'; |
|
|
|
import 'package:deep_voice/data/services/network/api.dart'; |
|
|
|
@ -126,11 +125,11 @@ class AgentController extends GetxController { |
|
|
|
|
|
|
|
// 添加加载状态跟踪 |
|
|
|
final RxBool isLoadingMusic = false.obs; |
|
|
|
final RxString loadingMusicId = ''.obs; |
|
|
|
final RxInt loadingMusicId = 0.obs; |
|
|
|
|
|
|
|
// 设置加载状态的方法 |
|
|
|
void setLoadingMusic(String id, bool loading) { |
|
|
|
loadingMusicId.value = loading ? id : ''; |
|
|
|
void setLoadingMusic(int id, bool loading) { |
|
|
|
loadingMusicId.value = loading ? id : 0; |
|
|
|
isLoadingMusic.value = loading; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1333,7 +1332,7 @@ class AgentController extends GetxController { |
|
|
|
try { |
|
|
|
var status = await _musiceManager.getStatus(); |
|
|
|
isPlaying.value = status['isPlaying'] ?? false; |
|
|
|
currentId.value = status['id'] ?? 0; |
|
|
|
currentId.value = status['id'] as int; |
|
|
|
Logger.d('AgentController', |
|
|
|
'音乐状态更新: playing=${isPlaying.value}, url=${currentId.value}'); |
|
|
|
print("音乐状态更新: playing=${isPlaying.value}, url=${currentId.value}"); |
|
|
|
@ -1351,16 +1350,14 @@ class AgentController extends GetxController { |
|
|
|
isPlaying.value = true; |
|
|
|
// 修复:确保currentId接收int类型 |
|
|
|
final songId = song['id']; |
|
|
|
currentId.value = songId is int |
|
|
|
? songId |
|
|
|
: (int.tryParse(songId?.toString() ?? '0') ?? 0); |
|
|
|
currentId.value = songId ?? 0; |
|
|
|
|
|
|
|
// 重置进度状态 |
|
|
|
currentPosition.value = 0; |
|
|
|
duration.value = 0; |
|
|
|
progress.value = 0.0; |
|
|
|
|
|
|
|
final id = song['id'] ?? ""; |
|
|
|
final id = song['id'] ?? 0; |
|
|
|
final timestampMs = song['ts'] ?? 0; |
|
|
|
|
|
|
|
// 检查URL是否需要刷新(只有当有时间戳时才检查) |
|
|
|
@ -1382,9 +1379,7 @@ class AgentController extends GetxController { |
|
|
|
song["url"] = urldata['url'] ?? ''; |
|
|
|
// 修复:确保currentId接收int类型 |
|
|
|
final newSongId = song['id']; |
|
|
|
currentId.value = newSongId is int |
|
|
|
? newSongId |
|
|
|
: (int.tryParse(newSongId?.toString() ?? '0') ?? 0); |
|
|
|
currentId.value = newSongId ?? 0; |
|
|
|
Logger.d(TAG, '获取新URL成功'); |
|
|
|
} catch (e) { |
|
|
|
Logger.e(TAG, '获取新URL失败: $e'); |
|
|
|
@ -1394,8 +1389,8 @@ class AgentController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// 转换为MusicManager期望的格式 |
|
|
|
final musicData = <String, String>{ |
|
|
|
'id': song['id']?.toString() ?? '', |
|
|
|
final musicData = <String, dynamic>{ |
|
|
|
'id': song['id'], |
|
|
|
'url': song['url']?.toString() ?? '', |
|
|
|
'title': song['title']?.toString() ?? song['name']?.toString() ?? '', |
|
|
|
'artist': |
|
|
|
@ -1521,10 +1516,10 @@ class AgentController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// 获取播放进度 |
|
|
|
Future<void> updateMusicProgress1(String currentIdInternal, int newPosition, |
|
|
|
Future<void> updateMusicProgress1(int currentIdInternal, int newPosition, |
|
|
|
int newDuration, double newProgress) async { |
|
|
|
try { |
|
|
|
if (int.parse(currentIdInternal) != 0) { |
|
|
|
if (currentIdInternal != 0) { |
|
|
|
isPlaying.value = true; |
|
|
|
// return; // 如果没有在播放,直接返回 |
|
|
|
} |
|
|
|
@ -1533,11 +1528,11 @@ class AgentController extends GetxController { |
|
|
|
// final newPosition = progressInfo['currentPosition'] ?? 0; |
|
|
|
// final newDuration = progressInfo['duration'] ?? 0; |
|
|
|
// final newProgress = progressInfo['progress'] ?? 0.0; |
|
|
|
print( |
|
|
|
"updateMusicProgress1:currentIdInternal:$currentIdInternal newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
|
// print( |
|
|
|
// "updateMusicProgress1:currentIdInternal:$currentIdInternal newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
|
bool hasUpdate = false; |
|
|
|
if (currentId.value != int.parse(currentIdInternal)) { |
|
|
|
currentId.value = int.parse(currentIdInternal); |
|
|
|
if (currentId.value != currentIdInternal) { |
|
|
|
currentId.value = currentIdInternal; |
|
|
|
hasUpdate = true; |
|
|
|
} |
|
|
|
// 只有当值发生变化时才更新,避免不必要的UI刷新 |
|
|
|
@ -1610,7 +1605,7 @@ class AgentController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
// 跳转到指定位置 |
|
|
|
Future<void> seekToPosition1(String currentIdInternal, int newPosition, |
|
|
|
Future<void> seekToPosition1(int currentIdInternal, int newPosition, |
|
|
|
int newDuration, double newProgress) async { |
|
|
|
try { |
|
|
|
//await _musiceManager.seekTo(positionMs); |
|
|
|
@ -1676,7 +1671,7 @@ class AgentController extends GetxController { |
|
|
|
|
|
|
|
// 设置加载状态 |
|
|
|
isLoadingMusic.value = true; |
|
|
|
loadingMusicId.value = playlist[0]['id']?.toString() ?? ''; |
|
|
|
loadingMusicId.value = playlist[0]['id']; |
|
|
|
|
|
|
|
// 重置播放状态 |
|
|
|
isPlaying.value = true; |
|
|
|
@ -1687,7 +1682,7 @@ class AgentController extends GetxController { |
|
|
|
// 格式化歌曲列表数据 |
|
|
|
final formattedPlaylist = playlist.map((song) { |
|
|
|
return { |
|
|
|
'id': song['id']?.toString() ?? '', |
|
|
|
'id': song['id'], |
|
|
|
'url': song['url']?.toString() ?? '', |
|
|
|
'title': song['title']?.toString() ?? song['name']?.toString() ?? '', |
|
|
|
'artist': |
|
|
|
@ -1702,7 +1697,7 @@ class AgentController extends GetxController { |
|
|
|
|
|
|
|
// 更新当前播放歌曲ID |
|
|
|
if (formattedPlaylist.isNotEmpty) { |
|
|
|
currentId.value = int.tryParse(formattedPlaylist[0]['id'] ?? '0') ?? 0; |
|
|
|
currentId.value = formattedPlaylist[0]['id'] ?? 0; |
|
|
|
} |
|
|
|
|
|
|
|
// 启动进度定时器 |
|
|
|
@ -1726,7 +1721,7 @@ class AgentController extends GetxController { |
|
|
|
} finally { |
|
|
|
// 清除加载状态 |
|
|
|
isLoadingMusic.value = false; |
|
|
|
loadingMusicId.value = ''; |
|
|
|
loadingMusicId.value = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1778,7 +1773,7 @@ class AgentController extends GetxController { |
|
|
|
// 查找当前歌曲在列表中的索引 |
|
|
|
int index = -1; |
|
|
|
for (int i = 0; i < playlist.length; i++) { |
|
|
|
if (int.tryParse(playlist[i]['id']?.toString() ?? '0') == songId) { |
|
|
|
if (playlist[i]['id'] == songId) { |
|
|
|
index = i; |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -1837,10 +1832,10 @@ class AgentController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
/// 处理来自系统通知栏的跳转操作 |
|
|
|
Future<void> onMediaSessionSeekTo1(String currentIdInternal, int newPosition, |
|
|
|
Future<void> onMediaSessionSeekTo1(int currentIdInternal, int newPosition, |
|
|
|
int newDuration, double newProgress) async { |
|
|
|
print( |
|
|
|
"onMediaSessionSeekTo1 currentIdInternal :$currentIdInternal ,newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
|
// print( |
|
|
|
// "onMediaSessionSeekTo1 currentIdInternal :$currentIdInternal ,newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
|
await seekToPosition1( |
|
|
|
currentIdInternal, newPosition, newDuration, newProgress); |
|
|
|
} |
|
|
|
|