WeChat Mini Program API Music Playback Control
wx.getBackgroundAudioPlayerState(OBJECT)
Get the music playback status
success return parameter description:
Sample code:
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)
Play music, there can only be one piece of music at the same time Now Playing.
OBJECT parameter description
##Sample code
wx.playBackgroundAudio({ dataUrl: '', title: '', coverImgUrl: '' })wx.pauseBackgroundAudio()
Pause playing music
Sample code
wx.pauseBackgroundAudio()wx.seekBackgroundAudio(OBJECT)
Control music playback progress
OBJECT parameter description
Type | Required | Description | |
---|---|---|---|
Number | is | Music position, unit: seconds |
wx.seekBackgroundAudio({
position: 30})
wx.stopBackgroundAudio()
Sample code
wx.stopBackgroundAudio()
wx.onBackgroundAudioPlay(CALLBACK)
wx. onBackgroundAudioPause(CALLBACK)
Listen to music pausewx.onBackgroundAudioStop(CALLBACK)
Listen to music stop