小程式backgroundAudioManager.pause()無法停止播放的原因
阿新 • • 發佈:2018-11-08
var isMusicPlay = this.data.isMusicPlay; var postData = this.data.postData; var backgroundAudioManager = wx.getBackgroundAudioManager(); if(isMusicPlay) { backgroundAudioManager.pause(); this.setData({ isMusicPlay: false }) } else { //設定title,src等屬性不能放在外部, 否則可能會造成無法停止播放 backgroundAudioManager.title = postData.music.title; backgroundAudioManager.coverImgUrl = postData.music.coverImg; // 設定了 src 之後會自動播放 backgroundAudioManager.src = postData.music.url; backgroundAudioManager.play(); this.setData({ isMusicPlay: true }) }