WeChat Mini Program API Music Playback Control


wx.getBackgroundAudioPlayerState(OBJECT)


Get the music playback status

success return parameter description:

QQ截图20170208110749.png

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

QQ截图20170208110802.png

##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

##Parameterposition
TypeRequiredDescription
Number is Music position, unit: seconds
Sample code

wx.seekBackgroundAudio({
    position: 30})
wx.stopBackgroundAudio()

Stop playing music

Sample code

wx.stopBackgroundAudio()
wx.onBackgroundAudioPlay(CALLBACK)

Monitor music playback

wx. onBackgroundAudioPause(CALLBACK)

Listen to music pause

wx.onBackgroundAudioStop(CALLBACK)

Listen to music stop