- 聲明對象 使用微信小程序自帶背景音樂接口
const backgroundAudioManager = wx.getBackgroundAudioManager()
- 在小程序頁面加載時 播放
onLoad() {
this.player(backgroundAudioManager);
},
onunload() {
wx.stopBackgroundAudio();
},
- 定義循環(huán)播放方法
title src必填富岳,這里使用第三方網(wǎng)易云音樂接口, id可自己選想要的音樂
player(e) {
e.title = '惡作劇'
e.src = 'http://music.163.com/song/media/outer/url?id=xxxx.mp3'
e.onEnded(() => {
this.player(backgroundAudioManager)
})
},