RecorderManager

全局唯一的录音管理器

方法

RecorderManager.start(Object object)

开始录音

RecorderManager.pause()

暂停录音

RecorderManager.resume()

继续录音

RecorderManager.stop()

停止录音

RecorderManager.onStart(function callback)

监听录音开始事件

RecorderManager.onResume(function callback)

监听录音继续事件

RecorderManager.onPause(function callback)

监听录音暂停事件

RecorderManager.onStop(function callback)

监听录音结束事件

RecorderManager.onFrameRecorded(function callback)

监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。

RecorderManager.onError(function callback)

监听录音错误事件

RecorderManager.onInterruptionBegin(function callback)

监听录音因为受到系统占用而被中断开始事件。以下场景会触发此事件:微信语音聊天、微信视频聊天。此事件触发后,录音会被暂停。pause 事件在此事件后触发

RecorderManager.onInterruptionEnd(function callback)

监听录音中断结束事件。在收到 interruptionBegin 事件之后,小程序内所有录音会暂停,收到此事件之后才可再次录音成功。

示例代码

  1. const recorderManager = wx.getRecorderManager()
  2. recorderManager.onStart(() => {
  3. console.log('recorder start')
  4. })
  5. recorderManager.onPause(() => {
  6. console.log('recorder pause')
  7. })
  8. recorderManager.onStop((res) => {
  9. console.log('recorder stop', res)
  10. const { tempFilePath } = res
  11. })
  12. recorderManager.onFrameRecorded((res) => {
  13. const { frameBuffer } = res
  14. console.log('frameBuffer.byteLength', frameBuffer.byteLength)
  15. })
  16. const options = {
  17. duration: 10000,
  18. sampleRate: 44100,
  19. numberOfChannels: 1,
  20. encodeBitRate: 192000,
  21. format: 'aac',
  22. frameSize: 50
  23. }
  24. recorderManager.start(options)