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";;

Recommended Today

The use of springboot Ajax

Ajax overview What is Ajax? Ajax (asynchronous JavaScript and XML) is a web application client technology. It can communicate with the server application asynchronously with the help of client script (multiple threads can interact with the server at the same time). After obtaining the server data on demand, it can refresh the data locally, so […]