onMusicTap(event) {
let that = this
let node = this .data.node
let isPlayingMusic = node.isPlayingMusic
const backgroundAudioManager = app.globalData.backgroundAudioManager
node.isPlayingMusic = this .data.node.isPlayingMusic
node.stopPoint = processTotalDuration( this .data.node.listened)
backgroundAudioManager.onTimeUpdate(e => {
that.setData({
duration: processTotalDuration(backgroundAudioManager.duration),
currentTime: processTotalDuration(backgroundAudioManager.currentTime),
percent: parseInt(100 * (backgroundAudioManager.currentTime / backgroundAudioManager.duration))
})
app.globalData.g_trackAudioProgress.set(node.id, {
duration: backgroundAudioManager.duration,
stopPoint: backgroundAudioManager.currentTime
})
if (app.globalData.g_trackAudioProgress.get(node.id)) {
if (app.globalData.g_trackAudioProgress.get(node.id).stopPoint >= (app.globalData.g_trackAudioProgress.get(node.id).duration) - 3) {
app.globalData.g_trackAudioProgress.set(node.id, {
duration: backgroundAudioManager.duration,
stopPoint: 0,
})
}
}
console.log(app.globalData.g_trackAudioProgress.get(node.id))
})
this .triggerEvent( 'customevent' , node, {
bubbles: true
})
this .setMusicMonitor()
if (isPlayingMusic) {
backgroundAudioManager.pause(e => {
console.log( 'will plause' )
})
} else {
backgroundAudioManager.src = `${node.content}`
backgroundAudioManager.title = node.title
backgroundAudioManager.startTime = that.data.isFirstTap ? convertTimeToSeconds(that.data.node.listened) : app.globalData.g_trackAudioProgress.get(node.id) && app.globalData.g_trackAudioProgress.get(node.id).stopPoint
that.setData({
isFirstTap: false
})
console.log( 'will play' )
}
},
setMusicMonitor() { const backgroundAudioManager = app.globalData.backgroundAudioManager let that = this let node = this.data.node //点击播放图标和总控开关都会触发这个函数 wx.onBackgroundAudioPlay(e => { console.log('playing...') node.isPlayingMusic ? null : that.onMusicTap() }) wx.onBackgroundAudioPause(e => { console.log('pausing...') node.isPlayingMusic ? that.onMusicTap() : null }) wx.onBackgroundAudioStop(e => { if (app.globalData.g_trackAudioProgress.get(node.id)) { // 循环播放 TODO: if (app.globalData.g_trackAudioProgress.get(node.id).stopPoint >= app.globalData.g_trackAudioProgress.get(node.id).duration - 3) { app.globalData.g_trackAudioProgress.set(node.id, { duration: backgroundAudioManager.duration, stopPoint: 0 }) } } console.log('stopping...', app.globalData.g_trackAudioProgress.get(node.id)) node.isPlayingMusic ? that.onMusicTap() : null }) },
|