- 小程序是否支持多个音频同时播放
index.wxml [代码] [代码] [代码]<[代码][代码]button[代码] [代码]bindtap[代码][代码]=[代码][代码]"audioPlay"[代码][代码]>播放</[代码][代码]button[代码][代码]>[代码] [代码]<[代码][代码]button[代码] [代码]bindtap[代码][代码]=[代码][代码]"audioStop"[代码][代码]>暂停</[代码][代码]button[代码][代码]>[代码] [代码] [代码] index.js [代码]Page({[代码] [代码] [代码] [代码] [代码][代码]data: {[代码][代码] [代码][代码]file: [代码][代码]'http://stor.weixinhost.com/3/wxhost-files/30bd8a0448f55afccaceae543ef9850a63604d99.mp3'[代码][代码],[代码][代码] [代码][代码]bmg: [代码][代码]'http://stor.weixinhost.com/3/wxhost-files/4523ea1d7dd6068e2a15b43bcb143df67c281aef.mp3'[代码][代码] [代码][代码]},[代码] [代码] [代码] [代码] [代码][代码]onLoad () {[代码] [代码] [代码] [代码] [代码][代码]this[代码][代码].bmgAudio = wx.createInnerAudioContext()[代码][代码] [代码][代码]this[代码][代码].fileAudio = wx.createInnerAudioContext()[代码] [代码] [代码] [代码] [代码][代码]this[代码][代码].bmgAudio.src = [代码][代码]this[代码][代码].data.bmg[代码][代码] [代码][代码]this[代码][代码].fileAudio.src = [代码][代码]this[代码][代码].data.file[代码] [代码] [代码] [代码] [代码][代码]this[代码][代码].bmgAudio.onPlay(() => {[代码] [代码] [代码][代码]setTimeout(() => {[代码][代码] [代码][代码]this[代码][代码].fileAudio.play()[代码][代码] [代码][代码]}, 1500)[代码][代码] [代码][代码]})[代码] [代码] [代码] [代码] [代码][代码]this[代码][代码].fileAudio.onEnded(() => {[代码][代码] [代码][代码]setTimeout(() => {[代码][代码] [代码][代码]this[代码][代码].bmgAudio.stop()[代码][代码] [代码][代码]}, 1500)[代码][代码] [代码][代码]})[代码] [代码] [代码] [代码] [代码][代码]this[代码][代码].fileAudio.onStop(() => {[代码][代码] [代码][代码]setTimeout(() => {[代码][代码] [代码][代码]this[代码][代码].bmgAudio.stop()[代码][代码] [代码][代码]}, 1500)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码] [代码] [代码] [代码][代码]onHide () {[代码][代码] [代码][代码]this[代码][代码].bmgAudio = [代码][代码]null[代码][代码] [代码][代码]this[代码][代码].fileAudio = [代码][代码]null[代码][代码] [代码][代码]},[代码] [代码] [代码] [代码] [代码][代码]// 试听[代码][代码] [代码][代码]audioPlay () {[代码][代码] [代码][代码]this[代码][代码].bmgAudio.play()[代码][代码] [代码][代码]},[代码] [代码] [代码] [代码] [代码][代码]// 暂停[代码][代码] [代码][代码]audioStop () {[代码][代码] [代码][代码]this[代码][代码].fileAudio.stop()[代码][代码] [代码][代码]}[代码][代码]})[代码]上述代码在安卓和开发者工具中可以同时播放,在IOS中不可以 但是用 组件audio 可以同时播放2个音频 [代码] [代码] [代码]<[代码][代码]audio[代码] [代码]src[代码][代码]=[代码][代码]"{{file}}"[代码] [代码]>[代码] [代码]<[代码][代码]audio[代码] [代码]src[代码][代码]=[代码][代码]"{{file}}"[代码] [代码]>[代码] [代码] [代码]
2018-02-08 - 组件 audio 在ios上无法循环播放?
使用组件 audio 添加 loop 循环播放 在安卓上可以正常循环播放,ios 上不可以 <audio src="{{src}}" id="myAudio" Page({ data: { src: 'http://stor.weixinhost.com/3/wxhost-files/96abc8130c5eb6fc25232fc1aeba2291a66504e3.mp3', audioAction: { method: 'pause' } }, onShow () { this.setData({ audioAction: { method: 'play' } }) } })
2018-02-07