The method of utilizing this API is wx.stopBackgroundAudio(Object object).
Attributes | Types | Default value | Required | Note |
success | function | - | Not required | Callback function for successful interface invocation |
fail | function | - | Not required | Callback function for unsuccessful interface invocation |
complete | function | - | Not required | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method for utilizing this API is wx.seekBackgroundAudio(Object object)
Attributes | Types | Default value | Required | Note |
position | number | - | Supported | Music position, measured in seconds |
success | function | - | Not required | Callback function for successful interface invocation |
fail | function | - | Not required | Callback function for unsuccessful interface invocation |
complete | function | - | Not required | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.seekBackgroundAudio({position: 30})
The method for employing this API is wx.playBackgroundAudio(Object object)
Attributes | Types | Default value | Required | Note |
dataUrl | string | - | Supported | Music link, currently supporting formats include m4a, aac, mp3, wav |
title | string | - | Not required | Music Title |
coverImgUrl | string | - | Not required | Cover URL |
success | function | - | Not required | Callback function for successful interface invocation |
fail | function | - | Not required | Callback function for unsuccessful interface invocation |
complete | function | - | Not required | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.playBackgroundAudio({dataUrl: '',title: '',coverImgUrl: ''})
The method for utilizing this API is wx.pauseBackgroundAudio(Object object)
Attributes | Types | Default value | Required | Note |
success | function | - | Not required | Callback function for successful interface invocation |
fail | function | - | Not required | Callback function for unsuccessful interface invocation |
complete | function | - | Not required | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
The method for utilizing this API is wx.onBackgroundAudioStop(function listener)
The method for utilizing this API is wx.onBackgroundAudioPlay(function listener)
The method for utilizing this API is wx.onBackgroundAudioPause(function listener)
The method for utilizing this API is wx.getBackgroundAudioPlayerState(Object object)
Attributes | Types | Default value | Required | Note |
success | function | - | Not required | Callback function for successful interface invocation |
fail | function | - | Not required | Callback function for unsuccessful interface invocation |
complete | function | - | Not required | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attributes | Types | Note |
duration | number | The length of the selected audio (in seconds), returned only during music playback. |
currentPosition | number | Selects the playback position of the audio (in s), only returned when the music is playing |
status | number | Playback status, valid values: 0: Paused 1: Playing 2: No music playing |
downloadPercent | number | The percentage of 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}})
Types | Note |
string src | The data source of the audio. Default is empty string, when new src is set, it will start playing automatically, currently supported formats are m4a, aac, mp3, wav |
number startTime | The position where the audio starts playing, unit: s. |
string title | Audio title, used for the native audio player's audio title (required). The share function in the native audio player, the title of the shared card, will also use this value. |
string epname | Album name, the share function in the native audio player, the description of the shared card, will also use this value. |
string singer | Singer's name, the share function in the native audio player, the description of the shared card, will also use this value. |
string coverImgUrl | Cover image URL, used as the background image for the native audio player. The share function in the native audio player, the accompanying image and background of the shared card will also use this image. |
string webUrl | Page link, the share function in the native audio player, the description of the shared card, will also use this value. |
string protocol | Audio protocol. The default value is 'http', setting 'hls' can support the playback of live audio using the HLS protocol. |
number playbackRate | Playback speed. Range 0.5-2.0, default is 1 (Android requires version 6 or above). |
number duration | The length of the current audio (unit: s), only returned when there is a valid src (read-only). |
number currentTime | The current playback position of the audio (unit: s), only returned when there is a valid src (read-only). |
boolean paused | Whether it is currently paused or stopped (read-only). |
number buffered | The time the audio has been buffered, it only guarantees that the content from the current playback time to this point has been buffered (read-only). |
The usage of this method is BackgroundAudioManager.onCanplay(function listener).
The usage of this method is BackgroundAudioManager.onEnded(function listener).
The usage of this method is BackgroundAudioManager.onError(function listener).
The usage of this method is BackgroundAudioManager.onNext(function listener).
The usage of this method is BackgroundAudioManager.onPause(function listener).
The usage of this method is BackgroundAudioManager.onPlay(function listener).
The usage of this method is BackgroundAudioManager.onPrev(function listener).
The usage of this method is BackgroundAudioManager.onSeeked(function listener).
The usage of this method is BackgroundAudioManager.onSeeking(function listener).
The usage of this method is BackgroundAudioManager.onStop(function listener).
The usage of this method is BackgroundAudioManager.onTimeUpdate(function listener).
The usage of this method is BackgroundAudioManager.onWaiting(function listener).
The usage of this method is BackgroundAudioManager.pause().
Error Codes | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the response header is missing the Content-Length. |
10004 | - | Invalid format |
-1 | - | An unknown error occurred. |
The method is utilized as BackgroundAudioManager.play().
The method is employed as BackgroundAudioManager.seek(number currentTime).
Error Codes | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the response header is missing the Content-Length. |
10004 | - | Invalid format |
-1 | - | An unknown error occurred. |
The method is implemented as BackgroundAudioManager.stop().
Error Codes | Error Message | Note |
10001 | - | System error |
10002 | - | Network Error |
10003 | - | File error, please verify if the response header is missing the Content-Length. |
10004 | - | Invalid format |
-1 | - | An unknown error occurred. |
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?