微信小程式開發(fā)文檔
/ 微信小程序API 音樂播放控制
微信小程序API 音樂播放控制
wx.getBackgroundAudioPlayerState(OBJECT)
獲取音樂播放狀態(tài)
success返回參數(shù)說明:
示例代碼:
wx.getBackgroundAudioPlayerState({ success:function(res){ var status = res.status; var dataUrl = res.dataUrl; var currentPosition = res.currentPosition; var duration = res.duration; var downloadPercent = res.downloadPercent; } })
wx.playBackgroundAudio(OBJECT)
播放音樂,同時只能有一首音樂正在播放。
OBJECT參數(shù)說明
示例代碼
wx.playBackgroundAudio({ dataUrl: '', title: '', coverImgUrl: '' })
wx.pauseBackgroundAudio()
暫停播放音樂
示例代碼
wx.pauseBackgroundAudio()
wx.seekBackgroundAudio(OBJECT)
控制音樂播放進度
OBJECT參數(shù)說明
參數(shù) | 類型 | 必填 | 說明 |
---|---|---|---|
position | Number | 是 | 音樂位置,單位:秒 |
示例代碼
wx.seekBackgroundAudio({ position: 30})
wx.stopBackgroundAudio()
停止播放音樂
示例代碼
wx.stopBackgroundAudio()
wx.onBackgroundAudioPlay(CALLBACK)
監(jiān)聽音樂播放
wx.onBackgroundAudioPause(CALLBACK)
監(jiān)聽音樂暫停
wx.onBackgroundAudioStop(CALLBACK)
監(jiān)聽音樂停止