This article shares the specific code for mini-program recording function for your reference. The specific content is as follows
First judge permissions
getPermission: function() { var that = this; ({ success(res) { () if ([""] === false) { ({ title: 'Whether to record', content: 'Whether to record', success: function (tip) { if () { ({ success: function (data) { if ([""] === true) { ({ title: 'Authorization Successful', icon: 'success', duration: 1000 }) () //After the authorization is successful, call chooseLocation and select the place } else { ({ title: 'Authorization failed', icon: 'success', duration: 1000 }) } } }) } } }) }else{ () } } }) },
Recording starts after authorization is successful
startLuYin(){ const options = { duration: 10000 * 6 * 10, //Specify the recording duration, unit ms sampleRate: 16000, //Sampling rate numberOfChannels: 1, //Number of recording channels encodeBitRate: 96000, //Coding rate format: 'mp3', //Audio format, valid value aac/mp3 frameSize: 50, //Specify the frame size, unit KB } //Start recording (options); (() => { ('recorder start'); Countdown(this); //Start timing }); //Error callback ((res) => { ('Recorder error:' + res); (res); clearTimeout(timer); //Stop timing when an error occurs }) },
Pause recording
// Pause recording pause: function() { var that = this; () ((res) => { (res) ('Pause recording') clearTimeout(timer); }) },
Continue recording
//Continue recording jixu: function() { var that = this; () Countdown(that); //Start timing ((res) => { }) },
Stop recording
//Stop recording stop: function() { (); ((res) => { = ; ('Stop recording', ) clearTimeout(timer); }) },
Play sound
//Play the sound play: function() { = true = , (() => { ('Start play') }) ((res) => { () () }) },
// Countdownfunction Countdown(that) { timer = setTimeout(function() { ("----secondes----" + formatSeconds(secondes)); secondes++; if (secondes >= 600) { (); clearTimeout(timer); } ({ times: formatSeconds(secondes) }); Countdown(that); }, 1000); };
// Time displayfunction formatSeconds(value) { var secondTime = parseInt(value); // Second var minuteTime = 0; // point var hourTime = 0; // Hour if (secondTime > 60) { //If the number of seconds is greater than 60, convert the number of seconds into an integer //Get minutes, divide by 60 to get integer minutes to get integer minuteTime = parseInt(secondTime / 60); //Get the number of seconds, take the number of seconds, get the integer number of seconds secondTime = parseInt(secondTime % 60); //If the minute is greater than 60, convert the minute into hours if (minuteTime > 60) { //Get the hours, get the minutes divided by 60, get the integer hours hourTime = parseInt(minuteTime / 60); //Get the points after the hour, get the points after the minute, divide the points by 60 to get the points after the minute, get the points after the minute. minuteTime = parseInt(minuteTime % 60); } } var result; //The time display method is 00:00 if (secondTime < 10) { result = "0" + parseInt(secondTime); } else { result = "" + parseInt(secondTime); } if (minuteTime > 0) { if (minuteTime < 10) { result = "0" + parseInt(minuteTime) + ":" + result; } else { result = "" + parseInt(minuteTime) + ":" + result; } } else { result = "00:" + result; } //Because the limit is up to three minutes, it is less than an hour if (hourTime > 0) { result = "" + parseInt(hourTime) + ":" + result; } return result; }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.