最新消息, 近日, 微信官方对小程序组件进行两个调整,给用户提供更自主的选择权。 1 打开其他小程序组件上线,用户点击后就可以直接跳转到其他小程序了。 2 新增打开小程序设置页组件,用户点击后可以进入设置页管理自己的各项授权信息。 ■开发者
1.小程序录音管理介绍 wx.getRecorderManager()基础库 1.6.0开始支持,低版本需做兼容处理,获取全局唯一的录音管理器recorderManager。2.小程序录音管理代码
// 录音管理let record = function (recorderManager) {this.recorderManager = recorderManagerthis.recordStart()}record.prototype = {// 开始录音start: function (startObj) {this.recorderManager.start(startObj)},//录音开始事件recordStart: function () {this.recorderManager.onStart(() => {console.log(this.recorderManager,'this.recorderManager')})}}3.Page onLoad配置
//录音管理,new 出 第二阶段的实例recorderManager = wx.getRecorderManager()that.newRecord = new record(recorderManager) that.newRecord.recorderManager.onStop((res) => { console.log(res,'获取录制完的链接')})//播放录音innerAudioContext = wx.createInnerAudioContext()innerAudioContext.onEnded(() => {console.log("音频自然播放结束")})4.现在开始录音
startRecord() {let that = this,startObj = {duration: 60000,sampleRate: 44100,numberOfChannels: 1,encodeBitRate: 192000,format: 'mp3',frameSize: 50}//录音开始that.newRecord.start(startObj)// 录音计时器recordTimeInterval = setInterval(function () {},1000)},5.停止录音
stopRecord() {clearInterval(recordTimeInterval);//停止录音事件this.newRecord.recorderManager.stop()}6.播放录音
// 播放录音playVoice(e) {let that = thislet srcPath = e.currentTarget.dataset.temppath,// 点击当前传递的播放链接duration = e.currentTarget.dataset.duration,// 录音时间index = e.currentTarget.dataset.index // 索引checkArr[index] = srcPath //用于页面判断播放一个,另一个暂停// 播放innerAudioContext.obeyMuteSwitch = falseinnerAudioContext.src = srcPathinnerAudioContext.play()// 时间减少器playTimeInterval = setInterval(() => {let playTime = that.data.playTime += 1},1000)}7.停止播放
// 停止播放stopVoice(forIndex,e) {let index;e !== undefined ? index = e.currentTarget.dataset.index : index = forIndexclearInterval(playTimeInterval)checkArr[index] = undefinedinnerAudioContext.stop()}8.只能播放一个的代码
// 只能播放一个onePlayFor(tempFilePath,src) {tempFilePath.forEach((el,i) => {if (el.tempFilePath !== src) {this.stopVoice(i)}})}
录音与停止录音使用小程序bind:touchstart='startRecord' bind:touchend='stopRecord' 事件
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!