Skip to main content
Version: Next

Taro.getBackgroundAudioPlayerState(option)

Gets the background music playback status.

NOTE: As of base library 1.2.0, the API is not maintained. Please use Taro.getBackgroundAudioManager instead.

Reference

Type

(option?: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
currentPositionnumberThe position where the playback of the selected audio has got to (in sec). It is only returned duing the music playback.
dataUrlstringThe song's URL. It is only returned during the music playback.
downloadPercentnumberThe download progress percentage of an audio file. It is only returned during the music playback.
durationnumberThe duration of the selected audio (in sec). It is only returned during the music playback.
status0 | 1 | 2Playback status
errMsgstringCall result

status

PropertyDescription
0Pausing
1Playing
2No music is playing

Sample Code

Taro.getBackgroundAudioPlayerState({
success: function (res) {
var status = res.status
var dataUrl = res.dataUrl
var currentPosition = res.currentPosition
var duration = res.duration
var downloadPercent = res.downloadPercent
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getBackgroundAudioPlayerState✔️