Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API background audio - get background playback status


May 18, 2021 WeChat Mini Program Development Document


Table of contents


wx.getBackgroundAudioPlayerState(Object object)

Starting with base library 1.2.0, this interface is out of maintenance, using wx.getBackgroundAudioManager instead

Gets the background music playback status.

Parameters

Object object

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.success callback function

Parameters
Object res
Property Type Description
duration number The length of the selected audio (in s) and returns only when the music is playing
currentPosition number The selected audio playback location (in s) and returns only when the music is playing
status number Play status
downloadPercent number The percentage of audio download progress that is returned only when the music is playing
dataUrl string Song data link, returned only when the music is playing

The legal value of res.status

Value Description The lowest version
0 Paused
1 Played
2 No music is playing

The sample code

wx.getBackgroundAudioPlayerState({
  success (res) {
    const status = res.status
    const dataUrl = res.dataUrl
    const currentPosition = res.currentPosition
    const duration = res.duration
    const downloadPercent = res.downloadPercent
  }
})