为了账号安全,请及时绑定邮箱和手机立即绑定

微信小程序测试音乐播放状态时我的全局判断条件没有执行到,谁能看看到底出了什么问题?我的判断条件如下:

微信小程序测试音乐播放状态时我的全局判断条件没有执行到,谁能看看到底出了什么问题?我的判断条件如下:

普罗斯 2017-02-06 12:39:23
当我在测试音乐播放状态时我的全局判断条件没有执行到,导致最后音乐正在播放时从另外一篇文章进入详情页音乐图标还是暂停状态,这是为啥呢?我检查了调试很久还是没弄出来,代码和七月老师的是一模一样的,谁能看看到底出了什么问题?我的判断条件如下:        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        })    }})
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 2781 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信