RecorderManager.js 743 Bytes
class RecorderManager {
  startOptions = {
    duration: 600000, //默认10分钟
    sampleRate: 16000,
    numberOfChannels: 1
  }
  constructor({ onStart, onStop, onError }) {
    this.recorderManager = uni.getRecorderManager()
    this.onStart = onStart
    this.onStop = onStop
    this.onError = onError
  }
  init() {
    this.recorderManager.onStart(() => {
      this.onStart()
    })
    this.recorderManager.onError(err => {
      this.onError(err)
    })
    this.recorderManager.onStop(res => {
      this.onStop(res)
    })
  }
  start(options) {
    const opt = Object.assign({}, this.startOptions, options)
    this.recorderManager.start(opt)
  }
  stop() {
    this.recorderManager.stop()
  }
}
export default RecorderManager