安卓系统不触发背景音乐播放器的stop及pause回调
发布于 6 年前 作者 yuping 3636 次浏览 来自 问答
setMusicMonitor() {
        let that = this
        let node = this.data.nodes.find(x => x.id === that.data.audioId)
        const backgroundAudioManager = app.globalData.backgroundAudioManager
        wx.onBackgroundAudioPlay(e => {
            console.log('playing...')
            app.globalData.g_isBackgroundAudioManagerPaused = false
            node && !node.isPlayingMusic ? that.onMusicTap({
                currentTarget: node
            }) : null
        })
        wx.onBackgroundAudioPause(e => {
            console.log('pausing...')
            app.globalData.g_isBackgroundAudioManagerPaused = true
            node && node.isPlayingMusic ? that.onMusicTap({
                currentTarget: node
            }) : null
        })
        wx.onBackgroundAudioStop(e => {
            console.log('stopping...')
            let node = that.data.nodes.find(x => x.id === that.data.audioId)
            if (node) {
                // TODO: 关闭背景音乐 从头播放有bug
                // let meaningFulStopPoint = app.globalData.g_duration - app.globalData.g_listened < .5 ? app.globalData.g_duration : app.globalData.g_listened
                course.putCourseDuration(this.data.courseid, node.id, 1000 * convertTimeToSeconds(node.duration), 1000 * convertTimeToSeconds(node.duration), )
            }
            that.setData({
                nodes: that.data.nodes.map(x => {
                    if (x.id === that.data.audioId) {
                        x.isPlayingMusic = false
                        x.listened = processTotalDuration(0)
                        x.percent = 0
                    }
                    return x
                })
            })
            let nexAudio = that.data.nodes[that.data.nextAudioIndex]
            that.onMusicTap({
                currentTarget: nexAudio
            })
        })
    },
2 回复

楼主解决了吗???

求解,

还有是怎么控制系统的上一首下一首呢

回到顶部