Method of playing cached audio files by wechat applet in IOS

Time:2020-10-14

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') {
   this.audio = wx.getBackgroundAudioManager()
  } else {
   this.audio = wx.createInnerAudioContext();
  }

  this.audio.title  ="Music files";
  this.audio.src  ="Local file address";
  this.audio.play();