How does Mini Program play cached audio files?
This article mainly explains "how Mini Program can play cached audio files". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let's let the editor take you to learn how Mini Program can play cached audio files.
Many times we want to cache the data locally in advance to save bandwidth. But recently, I encountered some minor problems when dealing with WeChat Mini Programs playing audio files cached locally, and then we need to adopt different playback strategies for Android and IOS.
First of all, if you use audio tags to play online audio files, if the server does not achieve breakpoint continuation, IOS will not be able to play, this should be noted.
For audio cached in Mini Program (audio saved by wx.saveFile (OBJECT)), IOS can only be played through the API for playing background music. Other playback methods have not been successfully practiced, while for Android, the internal audio context innerAudioContext object can be played. Give the code:
Var res = wx.getSystemInfoSync ()
If (res.platform = = 'ios') {
This.audio = wx.getBackgroundAudioManager ()
} else {
This.audio = wx.createInnerAudioContext ()
}
This.audio.title = "Music File"
This.audio.src = "local file address"
This.audio.play ()
At this point, I believe you have a deeper understanding of "how Mini Program can play cached audio files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!