收藏
回答

安卓系统不触发背景音乐播放器的stop及pause回调

框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 Bug wx.getBackgroundAudioManager() 客户端 Android 6.6.6 1.9
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 个回答

  • 2018-07-02

    楼主解决了吗???

    求解,

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

    2018-07-02
    有用
    回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2018-05-09

    麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

    2018-05-09
    有用
    回复 1
    • Elliot
      Elliot
      2018-05-15
      怎么给你放进去呢???
      2018-05-15
      回复
登录 后发表内容