uni-app 小米手机触发onWaiting后onTimeUpdate不会再次触发
uni-app 小米手机触发onWaiting后onTimeUpdate不会再次触发
示例代码:
onTimeUpdate() {
const audioPlay = app.globalData.audioPlay;
if (app.globalData.audioType != 'audio') return null;
if (this.wait) {
this.wait = false;
this.setTime();
uni.hideLoading();
}
if (!this.isPlaying) {
this.isPlaying = true;
uni.hideLoading();
}
this.value = parseInt((audioPlay.currentTime / audioPlay.duration) * 100);
this.currentTime = this.$js.durationFormate(parseInt(audioPlay.currentTime), false);
},
// 音频加载事件
onWaiting() {
if (app.globalData.audioType != 'audio') return null;
if (!this.wait) {
this.$js.showLoading('加载中');
this.delTime();
}
this.wait = true;
},
操作步骤:
网络不好的情况下 onWaiting 触发 然后可以播放的时候 onTimeUpdate 方法触发
预期结果:
网络不好的情况下 onWaiting 触发 然后可以播放的时候 onTimeUpdate 方法触发
实际结果:
网络不好的情况下 onWaiting 触发
然后可以播放的时候 onTimeUpdate 未触发
bug描述:
全局背景音频。getBackgroundAudioManager
小米平台在触发onWaiting事件之后,onTimeUpdate不会在触发。
ios 手机触发onWaiting 后会一直触发onPlay。
更多关于uni-app 小米手机触发onWaiting后onTimeUpdate不会再次触发的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app 小米手机触发onWaiting后onTimeUpdate不会再次触发的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个已知的小米系统WebView内核兼容性问题。小米手机在音频缓冲恢复后,onTimeUpdate事件确实可能停止触发。
问题分析:
小米手机WebView内核在处理音频缓冲时,onWaiting触发后,音频播放器的内部状态可能没有正确恢复,导致onTimeUpdate事件流中断。
解决方案:
- 添加手动恢复机制:在
onWaiting恢复后,主动触发时间更新
onWaiting() {
if (app.globalData.audioType != 'audio') return null;
if (!this.wait) {
this.$js.showLoading('加载中');
this.delTime();
}
this.wait = true;
// 添加恢复监听
setTimeout(() => {
const audioPlay = app.globalData.audioPlay;
if (audioPlay && this.wait) {
audioPlay.onTimeUpdate(() => {
this.wait = false;
this.onTimeUpdate();
});
}
}, 500);
}
- 使用轮询作为备选方案:
data() {
return {
timeUpdateTimer: null
}
},
onWaiting() {
// ...原有代码
// 启动轮询检测
this.startTimeUpdatePolling();
},
startTimeUpdatePolling() {
if (this.timeUpdateTimer) clearInterval(this.timeUpdateTimer);
this.timeUpdateTimer = setInterval(() => {
const audioPlay = app.globalData.audioPlay;
if (audioPlay && !audioPlay.paused && !this.wait) {
this.onTimeUpdate();
}
}, 1000);
},
onTimeUpdate() {
// ...原有代码
// 正常触发时清除轮询
if (this.timeUpdateTimer) {
clearInterval(this.timeUpdateTimer);
this.timeUpdateTimer = null;
}
}
- 结合onCanplay事件:
onCanplay() {
if (this.wait) {
this.wait = false;
// 强制触发一次时间更新
this.onTimeUpdate();
}
}

