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.
Type
(option?: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property | Type | Required | Description |
|---|---|---|---|
| complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail | (res: any) => void | No | The callback function for a failed API call |
| success | (res: Result) => void | No | The callback function for a successful API call |
SuccessCallbackResult
| Property | Type | Description |
|---|---|---|
| currentPosition | number | The position where the playback of the selected audio has got to (in sec). It is only returned duing the music playback. |
| dataUrl | string | The song's URL. It is only returned during the music playback. |
| downloadPercent | number | The download progress percentage of an audio file. It is only returned during the music playback. |
| duration | number | The duration of the selected audio (in sec). It is only returned during the music playback. |
| status | 0 | 1 | 2 | Playback status |
| errMsg | string | Call result |
status
| Property | Description |
|---|---|
| 0 | Pausing |
| 1 | Playing |
| 2 | No 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
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.getBackgroundAudioPlayerState | ✔️ |