微信小程序—wx.getRecorderManager(录音管理)
2017-12-21 14:49
731 查看
我们实现一下微信小程序的录音功能,
这是之前的官方文档:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-record.html
注意:在1.6.0 版本开始,接口不再维护。建议使用能力更强的 wx.getRecorderManager 接口
地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/getRecorderManager.html
因此我们使用的使用 wx.getRecorderManager 接口:
1.效果图如下,
2.index.js中:
2.index.wxml中:
3.index.wxss中:
本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!
这是之前的官方文档:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-record.html
注意:在1.6.0 版本开始,接口不再维护。建议使用能力更强的 wx.getRecorderManager 接口
地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/getRecorderManager.html
因此我们使用的使用 wx.getRecorderManager 接口:
1.效果图如下,
2.index.js中:
//index.js //获取应用实例 const app = getApp() const recorderManager = wx.getRecorderManager() const innerAudioContext = wx.createInnerAudioContext() var tempFilePath; Page({ data: { }, //开始录音的时候 start: function () { const options = { duration: 10000,//指定录音的时长,单位 ms sampleRate: 16000,//采样率 numberOfChannels: 1,//录音通道数 encodeBitRate: 96000,//编码码率 format: 'mp3',//音频格式,有效值 aac/mp3 frameSize: 50,//指定帧大小,单位 KB } //开始录音 recorderManager.start(options); recorderManager.onStart(() => { console.log('recorder start') }); //错误回调 recorderManager.onError((res) => { console.log(res); }) }, //停止录音 stop: function () { recorderManager.stop(); recorderManager.onStop((res) => { this.tempFilePath = res.tempFilePath; console.log('停止录音', res.tempFilePath) const { tempFilePath } = res }) }, //播放声音 play: function () { innerAudioContext.autoplay = true innerAudioContext.src = this.tempFilePath, innerAudioContext.onPlay(() => { console.log('开始播放') }) innerAudioContext.onError((res) => { console.log(res.errMsg) console.log(res.errCode) }) }, onLoad: function () { }, })
2.index.wxml中:
<button bindtap="start" class='btn'>开始录音</button> <button bindtap="stop" class='btn'>停止录音</button> <button bindtap="play" class='btn'>播放录音</button>
3.index.wxss中:
.btn{ margin-top: 10rpx; }
本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!
相关文章推荐
- 小程序全新API-----wx.getRecorderManager()录音管理器的使用
- 小程序 wx.getRecorderManager 录音 to 语音识别
- 小程序 wx.getRecorderManager 录音 to 语音识别
- 微信小程序 wx.getUserInfo 解密 C# 代码 - 转
- 微信小程序wx.getImageInfo()如何获取图片信息
- 关于微信小程序 getBackgroundAudioManager 注意点
- 微信小程序 wx.getUserInfo 解密 C# 代码
- [转]wx.getUserInfo(OBJECT) 微信小程序 获取用户信息
- 微信小程序wx.getImageInfo()获取图片信息
- 微信小程序的选择收货地址、新增地址、地址管理等模块的总结(1)
- 微信小程序图表插件(wx-charts)
- 微信小程序 Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- 微信小程序wx.navigateTo页面不跳转
- 微信小程序 wx.request 出现 Failed to load resource: the server responded with a status of 400
- 微信小程序录音与播放录音功能
- 微信小程序getPhoneNumber快速获取用户手机号组件
- RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序”
- 微信小程序(5)wx:if 条件判断
- 微信小程序填坑:上传头像;wx.chooseImage,wx.uploadFile
- 微信小程序网络请求wx.request请求