用户点击播放按钮太快
if (_data.clickPlayAu
dioFunctionIsRuning){
return ;
}
_this.setData({
clickPlayAu
dioFunctionIsRuning: true
})
var _obj = _this.data.au
dioListObj;
const au
dioId = $this.currentTarget.dataset.au
dioid;
var backgroundAu
dioManager = wx.getBackgroundAu
dioManager();
if (_this.data.au
dioListObj[au
dioId].imgUrl == '../../images/play.png'){
console.log('转换至播放状态')
//切换所有播放按钮为暂停状态
for (var j in _this.data.au
dioListObj) {
if (j && _this.data.au
dioListObj[j]) {
_this.data.au
dioListObj[j].imgUrl = '../../images/play.png';
}
}
_this.setData({
au
dioListObj: _this.data.au
dioListObj,})
//暂停正在播放音乐
wx.stopBackgroundAu
dio();
_obj[au
dioId].imgUrl = '../../images/paused.png';
backgroundAu
dioManager.title = '测试';
//设置音乐开始时间
if (_this.data.au
dioListObj[au
dioId].currentProcessNum != 0){
backgroundAu
dioManager.startTime = _this.data.au
dioListObj[au
dioId].currentProcessNum;
}
backgroundAu
dioManager.src = _this.data.au
dioListObj[au
dioId].src;
_obj[au
dioId].canSlider = true;
backgroundAu
dioManager.play();
// 背景音频自然播放结束事件
backgroundAu
dioManager.onEnded(function () {
var _obj = _this.data.au
dioListObj;
_obj[au
dioId].imgUrl = '../../images/play.png';
_obj[au
dioId].currentProcess = 0;
_obj[au
dioId].currentProcessNum = 0;
_this.setData({
au
dioListObj: _obj
})
})
//背景音频播放进度更新事件
backgroundAu
dioManager.onTimeUpdate(function (callback) {
_obj = _this.data.au
dioListObj;
//设置总时长
if (_obj[au
dioId] && _obj[au
dioId].totalProcess && (_obj[au
dioId].totalProcess == '--:--' || _obj[au
dioId].totalProcess == '00:00')) {
console.log(_this.formatTime(backgroundAu
dioManager.duration))
_obj[au
dioId].totalProcess = _this.formatTime(backgroundAu
dioManager.duration);
_obj[au
dioId].totalProcessNum = backgroundAu
dioManager.duration;
_this.setData({
au
dioListObj: _obj
})
}
if (!_this.data.isMovingSlider) {
//更新进度
_obj[au
dioId].currentProcess = _this.formatTime(backgroundAu
dioManager.currentTime);
_obj[au
dioId].currentProcessNum = backgroundAu
dioManager.currentTime;
_this.setData({
au
dioListObj: _obj
})
}
})
} else if (_this.data.au
dioListObj[au
dioId].imgUrl == '../../images/paused.png'){
console.log('转换至暂停状态')
_obj[au
dioId].imgUrl = '../../images/play.png'
wx.pauseBackgroundAu
dio();
backgroundAu
dioManager.pause();
}
_this.setData({
au
dioListObj: _obj,clickPlayAu
dioFunctionIsRuning: false
})