流式数据请求优化。
This commit is contained in:
@@ -376,8 +376,7 @@ class TTSPlayer {
|
||||
// 微信小程序环境,使用背景音频管理器
|
||||
const isBackgroundAudioAvailable = this.initAudioManager()
|
||||
|
||||
// 重置音频状态
|
||||
this.isSpeaking.value = true
|
||||
// 重置音频状态,但不立即设置为正在播放,等待实际播放时再设置
|
||||
this.isPaused.value = false
|
||||
this.isComplete.value = false
|
||||
|
||||
@@ -391,7 +390,7 @@ class TTSPlayer {
|
||||
|
||||
// 直接设置src并播放
|
||||
this.backgroundAudioManager.src = url
|
||||
console.log('🎵 微信小程序背景音频开始播放');
|
||||
console.log('🎵 微信小程序背景音频开始加载');
|
||||
} else {
|
||||
// 降级方案:使用InnerAudioContext
|
||||
console.log('🔄 微信小程序:背景音频不可用,降级使用InnerAudioContext');
|
||||
@@ -403,7 +402,7 @@ class TTSPlayer {
|
||||
}
|
||||
|
||||
this.innerAudioContext = uni.createInnerAudioContext()
|
||||
this.innerAudioContext.autoplay = false
|
||||
this.innerAudioContext.autoplay = true // 设置自动播放,等音频加载完成后自动开始
|
||||
this.innerAudioContext.obeyMuteSwitch = false
|
||||
this.innerAudioContext.volume = 1.0
|
||||
|
||||
@@ -438,13 +437,11 @@ class TTSPlayer {
|
||||
|
||||
this.innerAudioContext.onCanplay(() => {
|
||||
console.log('🎵 微信小程序InnerAudioContext可以播放了')
|
||||
if (this.isSpeaking.value && !this.isPaused.value) {
|
||||
this.innerAudioContext.play()
|
||||
}
|
||||
// 不需要手动调用play,因为已经设置了autoplay
|
||||
})
|
||||
|
||||
this.innerAudioContext.src = url
|
||||
console.log('🎵 微信小程序InnerAudioContext开始播放');
|
||||
console.log('🎵 微信小程序InnerAudioContext开始加载');
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user