最近在开发小程序中,使用到了音频播放,如下:
const innerAudioContext = wx.createInnerAudioContext()
function Play(source) {
innerAudioContext.stop()
innerAudioContext.src = source
innerAudioContext.play()
}
function Stop() {
innerAudioContext.stop()
innerAudioContext.src = null
}
module.exports = {
Play: Play,
Stop: Stop
}
<view bindtap='playVoice' data-resource='{{item.resource}}'>
<view>
<image src='tupian.png' mode='aspectFit'></image> {{item.duration}}
</view>
</view>
const voicePlayer = require('./utils/player')
playVoice: function(event) {
var resource = event.currentTarget.dataset.resource;
voicePlayer.Play(resource);
},
|