This API is used via wx.stopBackgroundAudio(Object object).
Attribute | Type | Default value | Required | Note |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This API is used via wx.seekBackgroundAudio(Object object).
Attribute | Type | Default value | Required | Note |
position | number | - | Yes | Music position, measured in seconds |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.seekBackgroundAudio({position: 30})
This API is used via wx.playBackgroundAudio(Object object).
Attribute | Type | Default value | Required | Note |
dataUrl | string | - | Yes | Music link, currently supporting formats such as m4a, aac, mp3, wav. |
title | string | - | No | Music Title |
coverImgUrl | string | - | No | Cover URL |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.playBackgroundAudio({dataUrl: '',title: '',coverImgUrl: ''})
This API is used via wx.pauseBackgroundAudio(Object object).
Attribute | Type | Default value | Required | Note |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This method is used via wx.onBackgroundAudioStop(function listener).
This method is used via wx.onBackgroundAudioPlay(function listener).
This method is used via wx.onBackgroundAudioPause(function listener).
This API is used via wx.getBackgroundAudioPlayerState(Object object).
Attribute | Type | Default value | Required | Note |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Note |
duration | number | The length of the selected audio (in seconds), returned only during music playback. |
currentPosition | number | The playback position of the selected audio (in seconds), returned only during music playback via getBackgroundAudioManager. |
status | number | Playback status, whose valid values include: 0: Pausing 1: Playing 2: No music being played |
downloadPercent | number | The percentage of the audio download progress, returned only during music playback. |
dataUrl | string | Song data link, returned only during music playback. |
wx.getBackgroundAudioPlayerState({success (res) {const status = res.statusconst dataUrl = res.dataUrlconst currentPosition = res.currentPositionconst duration = res.durationconst downloadPercent = res.downloadPercent}})
Type | Note |
string src | The data source of the audio. By default, it is an empty string. When a new src is set, it will automatically start playing. The currently supported formats are m4a, aac, mp3, wav. |
number startTime | The position where the audio starts playing, in seconds. |
string title | Audio title, used for the native audio player's audio title (required). The sharing feature in the native audio player and the title of the shared card will also use this value. |
string epname | Album name, also used by the sharing feature in the native audio player and the description of the shared card. |
string singer | Artist name, also used by the sharing feature in the native audio player and the description of the shared card. |
string coverImgUrl | Cover image URL, used for the native audio player background. The shared card and background for the sharing feature in the native audio player will also use this image. |
string webUrl | Page link, also used by the sharing feature in the native audio player and the description of the shared card. |
string protocol | Audio protocol, with a default value of 'http'. Setting it to 'hls' can support the playback of live audio using the HLS protocol. |
number playbackRate | Playback speed, ranging from 0.5 to 2.0, defaulting to 1 (Android requires Version 6 or later). |
number duration | The length of the current audio (in seconds), only returned when there is a valid src (read-only). |
number currentTime | The current playback position of the audio (in seconds), only returned when there is a valid src (read-only). |
boolean paused | Indicates whether the current status is paused or stopped (read-only). |
number buffered | The time point that the audio is buffered to, ensuring content from the current playback point to this point has been buffered (read-only). |
string referrerPolicy | origin: Sends the complete referrer; no-referrer: Not to send. The format is fixed as https://servicewechat.com/{appid}/{version}/page-frame.html, where {appid} is the appid of the mini program, {version} is the version number of the mini program. A version number of 0 indicates a development version, trial version, or review version. A version number of devtools indicates a developer tool, and the rest are official versions. |
This method is used via BackgroundAudioManager.onCanplay(function listener).
This method is used via BackgroundAudioManager.onEnded(function listener).
This method is used via BackgroundAudioManager.onError(function listener).
This method is used via BackgroundAudioManager.onNext(function listener).
This method is used via BackgroundAudioManager.onPause(function listener).
This method is used via BackgroundAudioManager.onPlay(function listener).
This method is used via Monitors background audio playback error events.
This method is used via BackgroundAudioManager.onSeeked(function listener).
This method is used via BackgroundAudioManager.onSeeking(function listener).
This method is used via BackgroundAudioManager.onStop(function listener).
This method is used via BackgroundAudioManager.onTimeUpdate(function listener).
This method is used via BackgroundAudioManager.onWaiting(function listener).
This method is used via BackgroundAudioManager.pause().
Error code | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the responseheader lacks of the Content-Length. |
10004 | - | Incorrect format. |
-1 | - | Unknown error. |
This method is used via BackgroundAudioManager.play().
This method is used via BackgroundAudioManager.seek(number currentTime).
Error code | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the responseheader lacks of the Content-Length. |
10004 | - | Incorrect format. |
-1 | - | Unknown error. |
This method is used via BackgroundAudioManager.stop().
Error code | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the responseheader lacks of the Content-Length. |
10004 | - | Incorrect format. |
-1 | - | Unknown error. |
const backgroundAudioManager = wx.getBackgroundAudioManager()backgroundAudioManager.title = 'This Very Moment'backgroundAudioManager.epname = 'This Very Moment'backgroundAudioManager.singer = 'Xu Wei'backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'// After setting the src, it will play automatically.backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
Was this page helpful?