1、h5的audio.onTimeUpdate是多個都會執行,微信小程序會覆蓋,只執行最新一個。
方法1:給audio對象添加一個屬性,進度更新監聽要執行的方法數組audio.onTimeUpdateList。然后在需要啟動監聽的地方執行監聽,比如在播放事件onPlay中。再加個屬性onTimeUpdateExist,避免h5重復監聽。
//聲明進度更新事件
that.audio.onTimeUpdateList=[{name:that.modelName+"-audio",func:function(){
console.log("onTimeUpdate1");
// console.log("onTimeUpdate");
if (!that.seek) {
that.current = that.audio.currentTime
}
if (!that.duration) {
that.duration = that.audio.duration
}
}}];
//音頻播放事件 that.audio.onPlay(() => { console.log("onPlay"); //實現進度監聽事件//h5的audio.onTimeUpdate多個都會執行,微信小程序會覆蓋,只執行最新一個。 if(!that.audio.onTimeUpdateExist && that.audio.onTimeUpdateList){ that.audio.onTimeUpdateExist=true; //進度更新事件 that.audio.onTimeUpdate(() => { for (var i = 0; i < that.audio.onTimeUpdateList.length; i++) { that.audio.onTimeUpdateList[i].func(); } }) } })
2、在微信小程序使用audio.seek后,audio.onTimeUpdate監聽失效,在onSeeked使用audio的屬性例如paused、duration后恢復。
方法1:在完成進度設置事件onSeeked中或onCanplay事件中使用audio.paused。
//音頻完成更改進度事件
audioBottomInfo.audio.onSeeked(() => {
console.log("onSeeked:"+audioBottomInfo.audio.paused);
that.seek = false;
})