Current location - Music Encyclopedia - QQ Music - WeChat applet plays background music
WeChat applet plays background music

1. wx.getBackgroundAudioManager:

Get the globally unique background audio manager. The mini program switches to the background, and if the audio is playing, it can continue to play. However, the background state cannot manipulate the audio playback state by calling API.

Starting from WeChat client version 6.7.2, if you need to continue playing audio after the mini program switches to the background, you need to configure the requiredBackgroundModes attribute in app.json. It can take effect directly on the development version and trial version, and the official version needs to pass the review.

2. Pause music playback in onUnload and onHide events.

3. Call the playback event in onShow

4. In the playback end event, play again to achieve the effect of loop playback.