當我在測試音樂播放狀態時我的全局判斷條件沒有執行到,導致最后音樂正在播放時從另外一篇文章進入詳情頁音樂圖標還是暫停狀態,這是為啥呢?我檢查了調試很久還是沒弄出來,代碼和七月老師的是一模一樣的,誰能看看到底出了什么問題?我的判斷條件如下:? ? ? ? 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/150
提交
取消