May 18, 2021 WeChat Mini Program Development Document
BackgroundAudioManager instance, available at wx.getBackgroundAudioManager.
Audio data source (2.2.3 starts supporting cloud file IDs). The default is an empty string, which starts playing automatically when a new src is set, and currently supports formats such as m4a, aac, mp3, wav.
Where the audio starts playing, in s.
Audio title for native audio player audio title (required). The sharing feature in the native audio player, shared out of the card title, will also use this value.
The album name, the sharing feature in the native audio player, the card description shared out, will also use this value.
The singer's name, the sharing feature in the native audio player, will also use the value for the card profile shared out.
Cover image URL, used to make a background map of the native audio player. The sharing feature in the native audio player, the shared card drawings and background will also be used.
Page links, sharing features in native audio players, shared card profiles, will also use this value.
Base library 1.9.94 starts to support, and low versions need to be compatible.
The audio protocol. The default is 'http', and setting 'hls' can support the playback of live audio for the HLS protocol.
Bastronomy 2.11.0 began support, low version needs to do Compatibility 。
Play speed.Range 0.5-2.0, default is 1.(Android requires 6 and above version)
The length of the current audio (unit: s), only returns when there is legal SRC.(Read only)
The current audio playing position (unit: s), only returns when there is legal SRC.(Read only)
Whether it is currently suspended or stopped.(Read only)
The time the audio is buffered, only that the content is buffered from the current playback point in time to this point in time. (Read-only)
Listen for background audio to enter a playable state event. However, there is no guarantee that the back will play smoothly
The callback function for background audio that enters a playable state event
Listen for background audio to naturally play the end event
Background audio naturally plays the callback function that ends the event
Listen for background audio playback error events
The callback function for background audio playback error events
Listen to the user tap the next event (iOS only) on the system music playback panel
The user taps the callback function for the next event on the system music playback panel
Listen for background audio pause events
The callback function for the background audio pause event
Listen for background audio playback events
The callback function for background audio playback events
Listen to the user tap the last song event (iOS only) on the system music playback panel
The user taps the callback function of the last event on the system music playback panel
Listen for background audio to complete the jump operation event
The callback function for the background audio completion jump operation event
Listen for background audio to start the jump operation event
The background audio starts to jump the callback function of the action event
Listen for background audio stop events
The callback function for the background audio stop event
Listen for background audio to play progress update events, and only small programs call back when they are in the fore desk.
The callback function for the background audio playback progress update event
Listen for events in the audio load. It fires when audio needs to stop loading because there is not enough data
The callback function for events in the audio load
Pause the music
Error code | The error message | Description |
---|---|---|
10001 | System error | |
10002 | Network error | |
10003 | The file is wrong | |
10004 | The format is wrong | |
-1 |
Unknown error
|
Play music
Error code | The error message | Description |
---|---|---|
10001 | System error | |
10002 | Network error | |
10003 | The file is wrong | |
10004 | The format is wrong | |
-1 | Unknown error |
Jump to the specified location
Jump position, unit s. 3 bits after the exact number of points, which supports ms-level accuracy
Error code | The error message | Description |
---|---|---|
10001 | System error | |
10002 | Network error | |
10003 | The file is wrong | |
10004 | The format is wrong | |
-1 | Unknown error |
Stop the music
Error code | The error message | Description |
---|---|---|
10001 | System error | |
10002 | Network error | |
10003 | The file is wrong | |
10004 | The format is wrong | |
-1 | Unknown error |
const backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = '此时此刻'
backgroundAudioManager.epname = '此时此刻'
backgroundAudioManager.singer = '许巍'
backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
// 设置了 src 之后会自动播放
backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'