Method of playing cached audio files by wechat applet in IOS


Most of the time, we want to cache data locally in advance to save bandwidth. However, recently, we encountered some small problems in the process of playing the cached audio files by wechat applet, and then we need to adopt different playback strategies for Android and IOS.

First of all, if the audio tag is used to play online audio files, if the server does not achieve breakpoint continuous transmission, IOS cannot play. This needs to be noted.

For audio cached in applets( wx.saveFile For Android, the internal audio context inneraudiocontext object can be played. Code given:

var res = wx.getSystemInfoSync()
  if (res.platform == 'ios') { = wx.getBackgroundAudioManager()
  } else { = wx.createInnerAudioContext();
  }  ="Music files";  ="Local file address";;