|
|
@ -165,7 +165,7 @@ class AgentController extends GetxController { |
|
|
onPrevious: onMediaSessionPrevious, |
|
|
onPrevious: onMediaSessionPrevious, |
|
|
onSeekTo: onMediaSessionSeekTo, |
|
|
onSeekTo: onMediaSessionSeekTo, |
|
|
onStop: onMediaSessionStop, |
|
|
onStop: onMediaSessionStop, |
|
|
onStop1: onMediaSessionSeekTo1, |
|
|
onProgress: onMediaSessionProgress, |
|
|
); |
|
|
); |
|
|
Logger.d('AgentController', '媒体会话回调设置完成'); |
|
|
Logger.d('AgentController', '媒体会话回调设置完成'); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
@ -1307,7 +1307,6 @@ class AgentController extends GetxController { |
|
|
// 设置按住说话状态 |
|
|
// 设置按住说话状态 |
|
|
isPushToTalkActive.value = true; |
|
|
isPushToTalkActive.value = true; |
|
|
|
|
|
|
|
|
print("开始按住说话,状态已设置为true"); |
|
|
|
|
|
// 开始语音识别 |
|
|
// 开始语音识别 |
|
|
await AgentService.audioContinue(); |
|
|
await AgentService.audioContinue(); |
|
|
// await startVoiceInput(); |
|
|
// await startVoiceInput(); |
|
|
@ -1406,9 +1405,6 @@ class AgentController extends GetxController { |
|
|
await _updateMediaSessionMetadata(musicData); |
|
|
await _updateMediaSessionMetadata(musicData); |
|
|
await _updateMediaSessionPlaybackState(true); |
|
|
await _updateMediaSessionPlaybackState(true); |
|
|
|
|
|
|
|
|
// 启动进度定时器 |
|
|
|
|
|
_startProgressTimer(); |
|
|
|
|
|
|
|
|
|
|
|
Logger.d(TAG, '音乐播放启动成功'); |
|
|
Logger.d(TAG, '音乐播放启动成功'); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.e(TAG, '播放音乐失败: $e'); |
|
|
Logger.e(TAG, '播放音乐失败: $e'); |
|
|
@ -1439,7 +1435,6 @@ class AgentController extends GetxController { |
|
|
Logger.d('AgentController', '恢复播放音乐'); |
|
|
Logger.d('AgentController', '恢复播放音乐'); |
|
|
await _musiceManager.resume(); |
|
|
await _musiceManager.resume(); |
|
|
isPlaying.value = true; |
|
|
isPlaying.value = true; |
|
|
_startProgressTimer(); |
|
|
|
|
|
|
|
|
|
|
|
// 更新媒体会话播放状态 |
|
|
// 更新媒体会话播放状态 |
|
|
await _updateMediaSessionPlaybackState(true); |
|
|
await _updateMediaSessionPlaybackState(true); |
|
|
@ -1451,23 +1446,6 @@ class AgentController extends GetxController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 启动进度更新定时器 |
|
|
|
|
|
void _startProgressTimer() { |
|
|
|
|
|
_stopProgressTimer(); // 先停止现有定时器 |
|
|
|
|
|
|
|
|
|
|
|
Logger.d('AgentController', '启动播放进度定时器'); |
|
|
|
|
|
_progressTimer = Timer.periodic(const Duration(milliseconds: 500), (timer) { |
|
|
|
|
|
if (isPlaying.value && currentId.value != 0) { |
|
|
|
|
|
updateMusicProgress(); |
|
|
|
|
|
} else if (!isPlaying.value) { |
|
|
|
|
|
// 如果不在播放状态,停止定时器 |
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
_progressTimer = null; |
|
|
|
|
|
Logger.d('AgentController', '播放已停止,取消进度定时器'); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 停止进度更新定时器 |
|
|
// 停止进度更新定时器 |
|
|
void _stopProgressTimer() { |
|
|
void _stopProgressTimer() { |
|
|
if (_progressTimer != null) { |
|
|
if (_progressTimer != null) { |
|
|
@ -1478,45 +1456,7 @@ class AgentController extends GetxController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取播放进度 |
|
|
// 获取播放进度 |
|
|
Future<void> updateMusicProgress() async { |
|
|
Future<void> updateMusicProgress(int currentIdInternal, int newPosition, |
|
|
try { |
|
|
|
|
|
if (!isPlaying.value || currentId.value == 0) { |
|
|
|
|
|
return; // 如果没有在播放,直接返回 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// var progressInfo = await _musiceManager.getProgress(); |
|
|
|
|
|
// final newPosition = progressInfo['currentPosition'] ?? 0; |
|
|
|
|
|
// final newDuration = progressInfo['duration'] ?? 0; |
|
|
|
|
|
// final newProgress = progressInfo['progress'] ?? 0.0; |
|
|
|
|
|
|
|
|
|
|
|
// bool hasUpdate = false; |
|
|
|
|
|
|
|
|
|
|
|
// // 只有当值发生变化时才更新,避免不必要的UI刷新 |
|
|
|
|
|
// if (currentPosition.value != newPosition) { |
|
|
|
|
|
// currentPosition.value = newPosition; |
|
|
|
|
|
// hasUpdate = true; |
|
|
|
|
|
// } |
|
|
|
|
|
// if (duration.value != newDuration) { |
|
|
|
|
|
// duration.value = newDuration; |
|
|
|
|
|
// hasUpdate = true; |
|
|
|
|
|
// } |
|
|
|
|
|
// if ((progress.value - newProgress).abs() > 0.001) { |
|
|
|
|
|
// // 避免浮点数精度问题 |
|
|
|
|
|
// progress.value = newProgress; |
|
|
|
|
|
// hasUpdate = true; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 如果有进度更新,通知系统媒体会话更新进度信息 |
|
|
|
|
|
// if (hasUpdate) { |
|
|
|
|
|
// await _updateMediaSessionProgress(); |
|
|
|
|
|
// } |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
Logger.e('AgentController', '获取播放进度失败: $e'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取播放进度 |
|
|
|
|
|
Future<void> updateMusicProgress1(int currentIdInternal, int newPosition, |
|
|
|
|
|
int newDuration, double newProgress) async { |
|
|
int newDuration, double newProgress) async { |
|
|
try { |
|
|
try { |
|
|
if (currentIdInternal != 0) { |
|
|
if (currentIdInternal != 0) { |
|
|
@ -1524,12 +1464,6 @@ class AgentController extends GetxController { |
|
|
// return; // 如果没有在播放,直接返回 |
|
|
// return; // 如果没有在播放,直接返回 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// // var progressInfo = await _musiceManager.getProgress(); |
|
|
|
|
|
// 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"); |
|
|
|
|
|
bool hasUpdate = false; |
|
|
bool hasUpdate = false; |
|
|
if (currentId.value != currentIdInternal) { |
|
|
if (currentId.value != currentIdInternal) { |
|
|
currentId.value = currentIdInternal; |
|
|
currentId.value = currentIdInternal; |
|
|
@ -1597,20 +1531,17 @@ class AgentController extends GetxController { |
|
|
Future<void> seekToPosition(int positionMs) async { |
|
|
Future<void> seekToPosition(int positionMs) async { |
|
|
try { |
|
|
try { |
|
|
await _musiceManager.seekTo(positionMs); |
|
|
await _musiceManager.seekTo(positionMs); |
|
|
// 立即更新进度状态 |
|
|
|
|
|
// await updateMusicProgress(); |
|
|
|
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.e('AgentController', '跳转播放位置失败: $e'); |
|
|
Logger.e('AgentController', '跳转播放位置失败: $e'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 跳转到指定位置 |
|
|
// 跳转到指定位置 |
|
|
Future<void> seekToPosition1(int currentIdInternal, int newPosition, |
|
|
Future<void> seekToProgress(int currentIdInternal, int newPosition, |
|
|
int newDuration, double newProgress) async { |
|
|
int newDuration, double newProgress) async { |
|
|
try { |
|
|
try { |
|
|
//await _musiceManager.seekTo(positionMs); |
|
|
|
|
|
// 立即更新进度状态 |
|
|
// 立即更新进度状态 |
|
|
await updateMusicProgress1( |
|
|
await updateMusicProgress( |
|
|
currentIdInternal, newPosition, newDuration, newProgress); |
|
|
currentIdInternal, newPosition, newDuration, newProgress); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.e('AgentController', '跳转播放位置失败: $e'); |
|
|
Logger.e('AgentController', '跳转播放位置失败: $e'); |
|
|
@ -1700,9 +1631,6 @@ class AgentController extends GetxController { |
|
|
currentId.value = formattedPlaylist[0]['id'] ?? 0; |
|
|
currentId.value = formattedPlaylist[0]['id'] ?? 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 启动进度定时器 |
|
|
|
|
|
_startProgressTimer(); |
|
|
|
|
|
|
|
|
|
|
|
Logger.d(TAG, '音乐列表播放启动成功'); |
|
|
Logger.d(TAG, '音乐列表播放启动成功'); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.e(TAG, '播放音乐列表失败: $e'); |
|
|
Logger.e(TAG, '播放音乐列表失败: $e'); |
|
|
@ -1831,12 +1759,12 @@ class AgentController extends GetxController { |
|
|
_stopProgressTimer(); |
|
|
_stopProgressTimer(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 处理来自系统通知栏的跳转操作 |
|
|
/// 处理来自系统进度条 |
|
|
Future<void> onMediaSessionSeekTo1(int currentIdInternal, int newPosition, |
|
|
Future<void> onMediaSessionProgress(int currentIdInternal, int newPosition, |
|
|
int newDuration, double newProgress) async { |
|
|
int newDuration, double newProgress) async { |
|
|
// print( |
|
|
// print( |
|
|
// "onMediaSessionSeekTo1 currentIdInternal :$currentIdInternal ,newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
// "onMediaSessionProgress currentIdInternal :$currentIdInternal ,newPosition:$newPosition newDuration:$newDuration newProgress:$newProgress"); |
|
|
await seekToPosition1( |
|
|
await seekToProgress( |
|
|
currentIdInternal, newPosition, newDuration, newProgress); |
|
|
currentIdInternal, newPosition, newDuration, newProgress); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|