介绍
这篇文章主要介绍了微信小程序如何实现录音记录功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。
具体内容如下
布局
& lt; !——页面/记录/record.wxml祝辞 & lt; view> ,& lt; button 类才能=皌ui-menu-list" bindtap才能=皊tartRecordAac", type=才能“primary"祝辞录音开始(aac) & lt;/button> ,& lt; button 类才能=皌ui-menu-list" bindtap才能=皊tartRecordMp3", type=才能“primary"祝辞录音开始(mp3) & lt;/button> ,& lt; button 类才能=皌ui-menu-list", bindtap才能=皊topRecord", type=才能“primary"祝辞录音结束& lt;/button> ,& lt; button 类才能=皌ui-menu-list" bindtap才能=皃layRecord", 类型=皃rimary"才能在播放录音& lt;/button> & lt;/view>
样式:
/*,页面/记录/record.wxss */, .tui-menu-list { flex-direction:,才能行; 保证金才能:20 rpx; ,,填充:20 rpx; }
开始录音和停止录音
//,/记录/record.js页面 页面({ , ,/* * ,,*,页面的初始数据 ,,*/,,数据:{ , ,,}, , onLoad才能:function (选项),{ ,,,var that =, ,,,this.recorderManager =, wx.getRecorderManager (); ,,,this.recorderManager.onError (function (), { ,,,,,that.tip(“录音失败!“); ,,,}) ,,,this.recorderManager.onStop (function (res), { ,,,,,that.setData ({ ,,,,,,,src: res.tempFilePath ,,,,,}) ,,,,,console.log (res.tempFilePath) ,,,,,that.tip(“录音完成!“) ,,,}) ,,,this.innerAudioContext =, wx.createInnerAudioContext () ,,,this.innerAudioContext.onError ((res),=在{ ,,,,,that.tip(“播放录音失败!“) ,,,}) ,,}, ,//才能提示 提示:才能function (msg), { ,,,wx.showModal ({ ,,,,,cancelColor:, & # 39; cancelColor& # 39; ,,,,,标题:& # 39;提示& # 39;, ,,,,,内容:味精, ,,,,,showCancel:假的 ,,,}) ,,}, ,//才能录制aac startRecordAac才能:function (), { ,,,this.recorderManager.start ({ ,,,,,格式:& # 39;aac # 39; ,,,}) ,,}, ,//才能录制mp3 startRecordMp3才能:function (), { ,,,this.recorderManager.start ({ ,,,,,格式:& # 39;mp3 # 39; ,,,}) ,,}, ,//才能停止录音 stopRecord才能:function (), { ,,,this.recorderManager.stop () ,,}, ,//才能播放录音 playRecord才能:function (), { ,,,var that =, ,,,var src =this.data.src ,,,if (src=https://www.yisu.com/zixun/? { this.tip('请先录音”) 返回 } this.innerAudioContext。src=this.data.src this.innerAudioContext.play () } })
效果图:
感谢你能够认真阅读完这篇文章,希望小编分享的“微信小程序如何实现录音记录功能”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!