# wx.getBackgroundAudioManager
iOS SDK 1.1.2, Android Not yet supported
- Function: Get a globally unique background audio manager.
- Contact: This interface capability is provided in the Mini Program with the same name API Compatible with Mini programs with the same name. API The properties and methods of theClick for details。
- Features: Support App Synchronize the playback panel displayed in the system control center when audio is playedSupport audio to continue to play after the phone screen.
# Note
WeChat Developer Tool: Before invoking this interface capability, you need to project.miniapp.json
Open inMedia SDKandApplication configuration (info.plist related), as shown below.
# Return value
return BackgroundAudioManager Examples, which can be obtained by wx.getBackgroundAudioManager() Get.
The following shows only the new ability to invoke the interfaceRequiredOf the properties and methods, the rest of which can be referred toMini Program documentation。
# attribute
string src
The data source for the audio (2.2.3 Start supporting cloud file IDs). Defaults to an empty character string when the new src Will automatically start playing. Currently supported formats are m4a, aac, mp3, wav。
string title
Audio title, for native audio player audio title (required). The share function in the native audio player, the title of the shared card, will also use this value.
# method
BackgroundAudioManager.onNext(function listener)
Monitor user click next music event in system music play panel (iOS only)
BackgroundAudioManager.onPrev(function listener)
Monitor the user click on the last event in the system music player panel (iOS only)
# sample code
onLoad() {
const backgroundAudioManager = wx.getBackgroundAudioManager()
ackgroundAudioManager.onPause(() => {
console.log('timeout')
})
backgroundAudioManager.onPlay(() => {
console.log('Playing')
})
backgroundAudioManager.onNext(() => {
console.log('the user clicked on the next song in the control center. ')
})
backgroundAudioManager.onPrev(() => {
console.log('the user clicked on the previous song in the control center. ')
})
},
play() {
const backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = 'at this moment. '
backgroundAudioManager.singer = 'Xu Wei'
// Set the src And then it plays automatically.
backgroundAudioManager.src = 'https://xxx/xxx.mp3'
}