iphoneX录音失败operateRecorder:fail:start record fail?
发布于 4 年前 作者 rhan 10838 次浏览 来自 问答

iphoneX录音失败直接走onError,参数res的errCode:-66681

然后报错operateRecorder:fail:start record fail和audioQueue start fail

代码片段:https://developers.weixin.qq.com/s/qxZGUvmQ7Hnr

1 回复
const app = getApp()
// 录音配置
const recordOptions = {
  duration: 60000,
  numberOfChannels: 1,
  sampleRate: 16000,
  encodeBitRate: 96000,
  format: 'mp3',
  frameSize: 50,
  audioSource:'auto'          // 设置录音输入源   auto
}
Page({
  data: {
    recorderManager:{},
    player:{},
    recordList:[]
  },
  // 开始接触
  touchstart(){
    wx.vibrateShort({
      type:'heavy',
    })
    this.data.recorderManager.start(recordOptions)
  },
  touchmove(e){
    console.log(e)
  },
  touchend(e){
    console.log(111)
    this.data.recorderManager.stop()
  },
  touchcancel(){

  },
  disposeRecord(){
    this.data.recorderManager.onStart(() => {
      console.log('recorder start')
    })
    this.data.recorderManager.onPause(() => {
      console.log('recorder pause')
    })
    this.data.recorderManager.onStop((res) => {
      console.log('监听到录音结束')
      console.log('recorder stop', res)
      const { tempFilePath, duration } = res
      console.log(tempFilePath,duration)
      this.data.recordList.push(res)
      this.setData({
        recordList:this.data.recordList
      })
    })
    this.data.recorderManager.onFrameRecorded((res) => {
      const { frameBuffer } = res
      console.log('frameBuffer.byteLength', frameBuffer.byteLength)
    });
    this.data.recorderManager.onError((res)=>{
      console.log(res)  // errcode -66681
      // audioQueue start fail
      wx.showToast({
        icon:'info',
        title: '录音失败'+res.errMsg,
        duration: 1500
      })
    })
  },
  playOrPause(e){
    console.log(e)
    this.data.player.stop()
    this.data.player.src = e.target.dataset.item.tempFilePath
    this.data.player.play()
  },
  disposeVoice(){
    // play voice
    this.data.player.onPlay(() => {
      console.log('play voice')
      wx.vibrateShort();
    });
    this.data.player.onStop(() => {
      console.log('stop voice')
    })
    this.data.player.onEnded(() => {
      console.log('end voice')
    })
  },
  onLoad() {
    this.data.recorderManager = wx.getRecorderManager()
    this.disposeRecord()
    this.data.player = wx.createInnerAudioContext()
    this.disposeVoice()
    
  },
})

回到顶部