|
|
|
@ -73,7 +73,7 @@ class ChatController extends GetxController { |
|
|
|
// 记录最后一次活动时间 |
|
|
|
DateTime _lastActivityTime = DateTime.now(); |
|
|
|
|
|
|
|
final _player = AudioPlayer(); |
|
|
|
final player = AudioPlayer(); |
|
|
|
final RxString audiourl = ''.obs; |
|
|
|
final RxBool isPlay = false.obs; |
|
|
|
|
|
|
|
@ -157,6 +157,14 @@ class ChatController extends GetxController { |
|
|
|
// 订阅VoiceInteractionService事件 |
|
|
|
_subscribeToVoiceInteractionEvents(); |
|
|
|
|
|
|
|
player.playerStateStream.listen((state) async { |
|
|
|
if (state.processingState == ProcessingState.completed) { |
|
|
|
await player.seek(Duration.zero); |
|
|
|
player.pause(); |
|
|
|
isPlay.value = false; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 使用微任务在布局完成后自动滚动到底部 |
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) { |
|
|
|
_scrollToBottom(); |
|
|
|
@ -253,7 +261,7 @@ class ChatController extends GetxController { |
|
|
|
_historyService.saveHistory(agent.id!, messages.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
_player.dispose(); |
|
|
|
player.dispose(); |
|
|
|
|
|
|
|
super.onClose(); |
|
|
|
} |
|
|
|
@ -443,10 +451,10 @@ class ChatController extends GetxController { |
|
|
|
isPlay.value = false; |
|
|
|
if (audiourl.value != musicaudio['audiourl']) { |
|
|
|
audiourl.value = musicaudio['audiourl']; |
|
|
|
await _player.setUrl(musicaudio['audiourl']); |
|
|
|
_player.play(); |
|
|
|
await player.setUrl(musicaudio['audiourl']); |
|
|
|
player.play(); |
|
|
|
} else { |
|
|
|
_player.play(); |
|
|
|
player.play(); |
|
|
|
} |
|
|
|
isPlay.value = true; |
|
|
|
} catch (e) { |
|
|
|
@ -458,7 +466,7 @@ class ChatController extends GetxController { |
|
|
|
|
|
|
|
// 暂停播放音乐 |
|
|
|
void pause() async { |
|
|
|
await _player.pause(); |
|
|
|
await player.pause(); |
|
|
|
isPlay.value = false; |
|
|
|
} |
|
|
|
|
|
|
|
|