tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-03-25 18:15:56
Audio
Last updated: 2025-03-25 18:15:56
Note: If you are developing with a game engine, the engine may already have audio handling integrated. In that case, you should use the components provided by the game engine.

InnerAudio

InnerAudio provides a simple and efficient way to play audio, supporting streaming playback. It is suitable for playing larger audio files, such as background music.

Relevant APIs

Audio configuration:setInnerAudioOption

Example

const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.src = 'https://wx_test.mp3'; // Replace with your own link
innerAudioContext.loop = true; // Set to loop playback
// innerAudioContext.autoplay = true; // Automatically start playing when ready
innerAudioContext.onError(res => {
console.log('Error', res);
});
innerAudioContext.onPlay(() => {
console.log('Playback started')
});
innerAudioContext.onCanplay(() => {
console.log('Ready to play')
innerAudioContext.play(); // Start playback
});
innerAudioContext.onStop(() => {
console.log('Playback stopped')
})
innerAudioContext.onEnded(() => {
console.log('Playback ended')
});
innerAudioContext.pause(); // Pause
innerAudioContext.stop(); // Stop
innerAudioContext.destroy(); // Release audio resources

wx.onShow(() => {
innerAudioContext.play(); // Resume playback when the mini game returns to the foreground
})

wx.onAudioInterruptionEnd(function () {
innerAudioContext.play() //Resume playback after being interrupted by another event (e.g., a phone call)
})

Supported formats

The supported audio formats may vary between iOS and Android. For more information, please see Audio.

Usage Suggestions

Reusing existing audio instances

For the same sound effect, you should reuse existing audio instances instead of creating new ones.

Destroy unneeded audio instances promptly

If an audio instance is no longer needed, you can call InnerAudioContext.destroy() to destroy the instance and free up resources.

Limitation on simultaneous audio playback

Due to system limitations, a maximum of 10 audio files can be played simultaneously on Android. Any additional audio files will be handled with lossy processing, which is not noticeable to developers but should be avoided by minimizing the number of simultaneous audio playbacks.




Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon