# BackgroundAudioManager
BackgroundAudioManager Example, you can use the wx.getBackgroundAudioManager Get.
# attribute
# string src
Audio data source (2.2.3 Start supporting cloud file ID). Default is empty string,When a new src Will automatically start playingCurrently supported formats are m4a, aac, mp3, wav。
# number startTime
Where the audio starts playing (in s).
# string title
Audio title for native audio player audio title (required). The share function in the native audio player, which shares out the card title, will also use this value.
# string epname
Album names, sharing features in native audio players, and sharing out card profiles will also use this value.
# string singer
The name of the singer, the sharing function in the native audio player, and the sharing of the card profile will also use this value.
# string coverImgUrl
Cover picture URL, used to do native audio player background map. Native audio player in the sharing function, share out of the card layout and background will also use the map.
# string webUrl
Page links, sharing features in native audio players, and shared card profiles will also use this value.
# string protocol
Start from base library version 1.9.94. Please remaining backward compatible.
Audio protocol. Default value is 'http ', setting 'hls' Can support playback HLS Protocol live audio.
# number playbackRate
Start from base library version 2.11.0. Please remaining backward compatible.
Playback speed. range 0.5-2.0 by default 1。(Android Need 6 And above)
# number duration
Length of current audio (in s), only if there is a valid src Returns when. (Read Only)
# number currentTime
Current audio playback position (unit: s), only if there is a legitimate src Returns when. (Read Only)
# boolean paused
Whether the current pause or stop. (Read Only)
# number buffered
The time that the audio has been buffered, ensuring only that the content at this point in time is buffered. (Read Only)
# string referrerPolicy
Start from base library version 2.13.0. Please remaining backward compatible.
origin
: Send the full referrer no-referrer
: Do not send. Format fixed to https://servicewechat.com/{appid} /{version}/page-frame.html
Where {appid} For Mini Program appid,{version} Is the version number of the Mini Program, which is 0 Represents a development version, a trial version, and a review version with a version number of devtools Represented as developer tools and the rest as official versions
# method
# BackgroundAudioManager.play()
Play music
# BackgroundAudioManager.pause()
Pause the music
# BackgroundAudioManager.seek(number currentTime)
Jump to the specified location
# BackgroundAudioManager.stop()
Stop the music
# BackgroundAudioManager.onCanplay(function callback)
Listen for background audio to enter a playable state event. But it doesn't guarantee a smooth playback
# BackgroundAudioManager.onWaiting(function callback)
Listen for audio loading events. Triggered when audio needs to be stopped and loaded due to insufficient data
# BackgroundAudioManager.onError(function callback)
Listen for background audio playback error events
# BackgroundAudioManager.onPlay(function callback)
Listen for background audio playback events
# BackgroundAudioManager.onPause(function callback)
Listen for background audio pause events
# BackgroundAudioManager.onSeeking(function callback)
Listen to background audio start jump operation event
# BackgroundAudioManager.onSeeked(function callback)
Listen to background audio to complete jump operation event
# BackgroundAudioManager.onEnded(function callback)
Monitor background audio natural playback end event
# BackgroundAudioManager.onStop(function callback)
Listen for background audio stop event
# BackgroundAudioManager.onTimeUpdate(function callback)
Listen for background audio playback progress update event, only Mini Program in the foreground will callback.
# BackgroundAudioManager.onNext(function callback)
Listen to the user click on the next song event in the system music play panel (iOS only)
# BackgroundAudioManager.onPrev(function callback)
Listen to the user click on the previous event in the system music player panel (iOS only)
# sample code
const backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = "Here and now."
backgroundAudioManager.epname = "Here and now."
backgroundAudioManager.singer = Xu wei
backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpgMax_age=2592000'
// Set src And it will play automatically.
backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.with/M500001VfvsJ21xFqb.mp3guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'