不多说了,直接贴code
1 // 1.2版本以后便不在维护 2 wx.getBackgroundAudioManager({ 3 success:function(res){ 4 var status =res.status; 5 if(status!=1){ 6 // 没有在播放 7 8 }else{ 9 wx.pauseBackgroundAudio(); 10 } 11 } 12 }); 13 14 // 1.2版本以后推荐的 15 const backgroundAudioManager = wx.getBackgroundAudioManager() 16 17 if (backgroundAudioManager.paused == false) { 18 wx.pauseBackgroundAudio(); 19 } else { 20 backgroundAudioManager.title = newsData.initData[_this.data.newsid].music.title 21 backgroundAudioManager.epname = newsData.initData[_this.data.newsid].music.title 22 backgroundAudioManager.singer = ‘林俊杰‘ 23 backgroundAudioManager.coverImgUrl = ‘http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000‘ 24 backgroundAudioManager.src = newsData.initData[_this.data.newsid].music.url // 设置了 src 之后会自动播放 25 }