• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

微信小程序测试音乐播放状态时我的全局判断条件没有执行到,谁能看看到底出

当我在测试音乐播放状态时我的全局判断条件没有执行到,导致最后音乐正在播放时从另外一篇文章进入详情页音乐图标还是暂停状态,
这是为啥呢?我检查了调试很久还是没弄出来,代码和七月老师的是一模一样的,谁能看看到底出了什么问题?我的判断条件如下:


        if (app.globalData.g_isPlayingMusic && app.globalData.g_currentMusicPostId == postId) {
            // this.data.isPlayingMusic = true
            this.setData({
                isPlayingMusic: true
            })
        }


完整代码:


onMusicTap: function (event) {
        var currentPostId = this.data.currentPostId;
        var postData = postsData.postList[currentPostId];
        var isPlayingMusic = this.data.isPlayingMusic;
        if (isPlayingMusic) {
            wx.pauseBackgroundAudio();
            // this.data.isPlayingMusic = false;//flase代表暂停
            this.setData({
                isPlayingMusic: false
            })
        }
        else {
            wx.playBackgroundAudio({
                dataUrl: postData.music.url,
                title: postData.music.title,
                coverImgUrl: postData.music.coverUrl,
            })
            // this.data.isPlayingMusic = true;//true 代表播放
            this.setData({
                isPlayingMusic: true
            })
        }


        if (app.globalData.g_isPlayingMusic && app.globalData.g_currentMusicPostId == postId) {
            // this.data.isPlayingMusic = true
            this.setData({
                isPlayingMusic: true
            })
        }
        //监听音乐
        this.setMusicMonitor();


    },


    //监听音乐的状态是否与默认的状态一致
    setMusicMonitor: function () {
        var self = this;
        wx.onBackgroundAudioPlay(function () {
            self.setData({
                isPlayingMusic: true
            })
            app.globalData.g_isPlayingMusic = true;
            app.globalData.g_currentMusicPostId = self.data.currentPostId;
        })


        wx.onBackgroundAudioPause(function () {
            self.setData({
                isPlayingMusic: false
            })
            app.globalData.g_isPlayingMusic = false,
                app.globalData.g_currentMusicPostId = null
        })
    }
})

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!