.wxml
<button bindtouchstart="touchdown" bindtouchend="touchup">按住录音</button>
<button catchtap="play">播放录音</button>
.js
Page({
data: {
frequency:'',
},
//手指按下
touchdown: function (e) {
console.log("手指按下了...")
var that = this;
//开始录音
wx.startRecord({
success: function (res) {
that.setData({
frequency: res.tempFilePath
})
}
})
},
//手指抬起
touchup: function (e) {
console.log("手指抬起了...")
wx.stopRecord()
},
play:function(e){
wx.playVoice({
filePath: this.data.frequency,
success: function () {
wx.showToast({
title: '播放结束',
icon: 'none',
duration: 1000
})
}
})
},
})
对你有帮助的话记得收藏点赞,有什么问题欢迎评论留言。