How to use wx.getRecorderManager () recording Management in Mini Program
This article mainly shows you how to use wx.getRecorderManager () recording management in Mini Program. The content is simple and clear. I hope it can help you solve your doubts. Now let the editor take you to study and learn how to use wx.getRecorderManager () recording management in Mini Program.
1. Mini Program recording management introduction: wx.getRecorderManager () basic library 1.6.0 is supported, and the lower version needs to be compatible to obtain a globally unique recording manager recorderManager. two。 Mini Program recording management code / / recording management let record = function (recorderManager) {this.recorderManager = recorderManager this.recordStart ()} record.prototype = {/ / start recording start: function (startObj) {this.recorderManager.start (startObj)}, / / recording start event recordStart: function () {this.recorderManager.onStart (()) = > {console.log (this.recorderManager) 'this.recorderManager')})}} 3.Page onLoad configuration / / recording management New out the second stage instance recorderManager = wx.getRecorderManager () that.newRecord = new record (recorderManager) that.newRecord.recorderManager.onStop ((res) = > {console.log (res, 'get the recorded link')}) / / play the recording innerAudioContext = wx.createInnerAudioContext () innerAudioContext.onEnded (() = > {console.log ("end of natural audio playback")}) 4. Now start recording startRecord () {let that = this, startObj = {duration: 60000, sampleRate: 44100, numberOfChannels: 1, encodeBitRate: 192000, format: 'mp3' FrameSize: 50} / / recording start that.newRecord.start (startObj) / / recording timer recordTimeInterval = setInterval (function () {}, 1000)}, 5. Stop recording stopRecord () {clearInterval (recordTimeInterval); / / stop recording event this.newRecord.recorderManager.stop ()} 6. Play the recording / / play the recording playVoice (e) {let that = this let srcPath = e.currentTarget.dataset.temppath, / / Click the currently passed playback link duration = e.currentTarget.dataset.duration / / recording time index = e.currentTarget.dataset.index / / Index checkArr [index] = srcPath / / for page judgment to play a Another pause / / playback innerAudioContext.obeyMuteSwitch = false innerAudioContext.src = srcPath innerAudioContext.play () / / time reducer playTimeInterval = setInterval (() = > {let playTime = that.data.playTime + = 1}, 1000)} 7. Stop / / stop playing stopVoice (forIndex, e) {let index; e! = = undefined? Index = e.currentTarget.dataset.index: index = forIndex clearInterval (playTimeInterval) checkArr [index] = undefined innerAudioContext.stop ()} 8. Can only play one code / / can only play one onePlayFor (tempFilePath, src) {tempFilePath.forEach ((el) I) = > {if (el.tempFilePath! = = src) {this.stopVoice (I)}}) recording and stopping recording using Mini Program bind:touchstart='startRecord' bind:touchend='stopRecord' event above is about "how to manage wx.getRecorderManager () recording in Mini Program" If this article is helpful to you and you think it is well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more attention to the industry information channel.