最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

小程序?qū)崿F(xiàn)錄音功能

 更新時(shí)間:2020年09月22日 08:39:37   作者:一心只想  
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)錄音功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)錄音功能的具體代碼,供大家參考,具體內(nèi)容如下

首先判斷權(quán)限

getPermission: function() {
  var that = this;
    wx.getSetting({
     success(res) {
      console.log(res.authSetting)
      if (res.authSetting["scope.record"] === false) {
       wx.showModal({
        title: '是否錄音',
        content: '是否錄音',
        success: function (tip) {
         if (tip.confirm) {
          wx.openSetting({
           success: function (data) {
            if (data.authSetting["scope.record"] === true) {
             wx.showToast({
              title: '授權(quán)成功',
              icon: 'success',
              duration: 1000
             })
             that.startLuYin()
             //授權(quán)成功之后,再調(diào)用chooseLocation選擇地方
            } else {
             wx.showToast({
              title: '授權(quán)失敗',
              icon: 'success',
              duration: 1000
             })
            }
           }
          })
         }
        }
       })
      }else{
       that.startLuYin()
      }
     }
    })
 },

授權(quán)成功后開始錄音

startLuYin(){
  const options = {
   duration: 10000 * 6 * 10, //指定錄音的時(shí)長,單位 ms
   sampleRate: 16000, //采樣率
   numberOfChannels: 1, //錄音通道數(shù)
   encodeBitRate: 96000, //編碼碼率
   format: 'mp3', //音頻格式,有效值 aac/mp3
   frameSize: 50, //指定幀大小,單位 KB
  }
  //開始錄音
  recorderManager.start(options);
  recorderManager.onStart(() => {
   console.log('recorder start');
   Countdown(this); //開始計(jì)時(shí)
  });
  //錯(cuò)誤回調(diào)
  recorderManager.onError((res) => {
   console.log('recorder出錯(cuò):' + res);
   console.log(res);
   clearTimeout(timer); //出錯(cuò)時(shí)停止計(jì)時(shí)
  })
 },

暫停錄音

// 暫停錄音
 pause: function() {
  var that = this;
  recorderManager.pause()
  recorderManager.onPause((res) => {
   console.log(res)
   console.log('暫停錄音')
   clearTimeout(timer);
  })
 },

繼續(xù)錄音

//繼續(xù)錄音
 jixu: function() {
  var that = this;
  recorderManager.resume()
  Countdown(that); //開始計(jì)時(shí)
  recorderManager.onResume((res) => {
  })
 },

停止錄音

//停止錄音
 stop: function() {
  recorderManager.stop();
  recorderManager.onStop((res) => {
   this.tempFilePath = res.tempFilePath;
   console.log('停止錄音', res.tempFilePath)
   clearTimeout(timer);
  })
 },

播放聲音

//播放聲音
 play: function() {
  innerAudioContext.autoplay = true
  innerAudioContext.src = this.tempFilePath,
   innerAudioContext.onPlay(() => {
    console.log('開始播放')
   })
  innerAudioContext.onError((res) => {
   console.log(res.errMsg)
   console.log(res.errCode)
  })
 },
// 倒計(jì)時(shí)
function Countdown(that) {
 timer = setTimeout(function() {
  console.log("----secondes----" + formatSeconds(secondes));
  secondes++;
  if (secondes >= 600) {
   recorderManager.stop();
   clearTimeout(timer);
  }
  that.setData({
   times: formatSeconds(secondes)
  });
  Countdown(that);
 }, 1000);
};
// 時(shí)間展示
function formatSeconds(value) {
 var secondTime = parseInt(value); // 秒
 var minuteTime = 0; // 分
 var hourTime = 0; // 小時(shí)
 if (secondTime > 60) { //如果秒數(shù)大于60,將秒數(shù)轉(zhuǎn)換成整數(shù)
  //獲取分鐘,除以60取整數(shù),得到整數(shù)分鐘
  minuteTime = parseInt(secondTime / 60);
  //獲取秒數(shù),秒數(shù)取佘,得到整數(shù)秒數(shù)
  secondTime = parseInt(secondTime % 60);
  //如果分鐘大于60,將分鐘轉(zhuǎn)換成小時(shí)
  if (minuteTime > 60) {
   //獲取小時(shí),獲取分鐘除以60,得到整數(shù)小時(shí)
   hourTime = parseInt(minuteTime / 60);
   //獲取小時(shí)后取佘的分,獲取分鐘除以60取佘的分
   minuteTime = parseInt(minuteTime % 60);
  }
 }
 var result;
 //時(shí)間的展示方式為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;
 }
 //由于限制時(shí)長最多為三分鐘,小時(shí)用不到
 if (hourTime > 0) {
  result = "" + parseInt(hourTime) + ":" + result;
 }
 return result;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

洪泽县| 高邑县| 济南市| 苏尼特右旗| 高清| 芮城县| 达州市| 盐津县| 内乡县| 余江县| 石泉县| 连平县| 合作市| 建平县| 湖州市| 镇宁| 连州市| 邢台县| 北安市| 上杭县| 武义县| 罗山县| 大荔县| 新龙县| 辽宁省| 当涂县| 平阴县| 河北省| 西吉县| 温泉县| 青海省| 彭山县| 桃江县| 绥宁县| 汉川市| 鄂州市| 军事| 图木舒克市| 玉门市| 顺昌县| 西安市|