title: RecorderManager

sidebar_label: RecorderManager

The globally unique recording manager.

Reference

Methods

onError

Listens on the recording error event.

Reference

  1. (callback: OnErrorCallback) => void
Property Type Description
callback OnErrorCallback The callback function for the recording error event.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onError ✔️ ✔️

onFrameRecorded

Listens on the event that the file with specified frame size has been recorded. This event is called back if frameSize is set.

Reference

  1. (callback: OnFrameRecordedCallback) => void
Property Type Description
callback OnFrameRecordedCallback The callback function for the event that the file with specified frame size has been recorded

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onFrameRecorded ✔️

onInterruptionBegin

Listens on the event that recording interruption starts due to system occupation. This event is triggered by the following scenarios: WeChat voice chat and WeChat video chat. After this event is triggered, the recording is paused. The pause event is triggered after this event.

Reference

  1. (callback: (res: CallbackResult) => void) => void
Property Type Description
callback (res: CallbackResult) => void The callback function for the event that recording interruption starts due to system occupation.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onInterruptionBegin ✔️

onInterruptionEnd

Listens on the event that recording interruption ends. After the interruptionBegin event is received, all recording in the Mini Program is paused. After this event is received, recording can be started again.

Reference

  1. (callback: (res: CallbackResult) => void) => void
Property Type Description
callback (res: CallbackResult) => void The callback function for the event that recording interruption ends.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onInterruptionEnd ✔️

onPause

Listens on the event that recording pauses.

Reference

  1. (callback: (res: CallbackResult) => void) => void
Property Type Description
callback (res: CallbackResult) => void The callback function for the event that recording pauses.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onPause ✔️ ✔️

onResume

Listens on the event that recording resumes.

Reference

  1. (callback: (res: CallbackResult) => void) => void
Property Type Description
callback (res: CallbackResult) => void The callback function for the event that recording resumes.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onResume ✔️ ✔️

onStart

Listens on the event that recording starts.

Reference

  1. (callback: (res: CallbackResult) => void) => void
Property Type Description
callback (res: CallbackResult) => void The callback function for the event that recording starts.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onStart ✔️ ✔️

onStop

Listens on the event that recording ends.

Reference

  1. (callback: OnStopCallback) => void
Property Type Description
callback OnStopCallback The callback function for the event that recording ends.

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onStop ✔️ ✔️

pause

Pauses recording

Reference

  1. () => void

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.pause ✔️ ✔️

resume

Resumes recording

Reference

  1. () => void

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.resume ✔️ ✔️

start

Starts recording

Reference

  1. (option: StartOption) => void
Property Type
option StartOption

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.start ✔️ ✔️

stop

Stops recording

Reference

  1. () => void

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.stop ✔️ ✔️

Parameters

OnErrorCallback

The callback function for the recording error event.

  1. (result: OnErrorCallbackResult) => void
Property Type
result OnErrorCallbackResult

OnErrorCallbackResult

Property Type Description
errMsg string 错误信息

OnFrameRecordedCallback

The callback function for the event that the file with specified frame size has been recorded

  1. (result: OnFrameRecordedCallbackResult) => void
Property Type
result OnFrameRecordedCallbackResult

OnFrameRecordedCallbackResult

Property Type Description
frameBuffer ArrayBuffer Recording frame data
isLastFrame boolean Whether the current frame is the last frame before the end of recording

OnStopCallback

The callback function for the event that recording ends.

  1. (result: OnStopCallbackResult) => void
Property Type
result OnStopCallbackResult

OnStopCallbackResult

Property Type Description
duration number The duration of recording (in sec)
fileSize number The size of a recording file (in bytes)
tempFilePath string The temporary path to recording files

StartOption

Property Type Required Description
audioSource "auto" | "buildInMic" | "headsetMic" | "mic" | "camcorder" | "voice_communication" | "voice_recognition" No Specifies the audio source for recording. Available audio sources can be obtained via Taro.getAvailableAudioSources().
duration number No Recording duration (in ms). The maximum value is 600,000 (10 minutes).
encodeBitRate number No Encoding bitrate. Valid values are shown in the following table.
format "mp3" | "aac" No Audio format
frameSize number No Specifies the frame size (in KB). If this field is specified, the recorded file will be called back whenever reaching the specified frame size. If it is not specified, the recorded file will not be called back. Only MP3 format is supported.
numberOfChannels 1 | 2 No Number of recording channels
sampleRate 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000 No Sampling rate

audioSource

Valid values of object.audioSource

Property Description
auto Automatic setup. The mobile microphone is used by default. The headset microphone is automatically adopted when the headset is plugged in. This setup applies to all platforms.
buildInMic Mobile microphone for iOS only
headsetMic Headset microphone for iOS only
mic Microphone (if the headset is not plugged in, the mobile microphone is used; otherwise, the headset microphone is used) for Android only
camcorder Same as mic. Suitable for audio and video recording. For Android only.
voice_communication Same as mic. Suitable for real-time communication. For Android only.
voice_recognition Same as mic. Suitable for speech recognition. For Android only.

format

Valid values of object.format

Property Description
mp3 MP3 format
aac AAC format

numberOfChannels

Valid values of object.numberOfChannels

Property Description
1 1 channel
2 2 channels

sampleRate

Valid values of object.sampleRate

Property Description Encoding code rate
8000 8000 Hz sample rate 16000 ~ 48000
11025 11025 Hz sample rate 16000 ~ 48000
12000 12000 Hz sample rate 24000 ~ 64000
16000 16000 Hz sample rate 24000 ~ 96000
22050 22050 Hz sample rate 32000 ~ 128000
24000 24000 Hz sample rate 32000 ~ 128000
32000 32000 Hz sample rate 48000 ~ 192000
44100 44100 Hz sample rate 64000 ~ 320000
48000 48000 Hz sample rate 64000 ~ 320000

API Support

API WeChat Mini-Program H5 React Native
RecorderManager.onError ✔️ ✔️
RecorderManager.onFrameRecorded ✔️
RecorderManager.onInterruptionBegin ✔️
RecorderManager.onInterruptionEnd ✔️
RecorderManager.onPause ✔️ ✔️
RecorderManager.onResume ✔️ ✔️
RecorderManager.onStart ✔️ ✔️
RecorderManager.onStop ✔️ ✔️
RecorderManager.pause ✔️ ✔️
RecorderManager.resume ✔️ ✔️
RecorderManager.start ✔️ ✔️
RecorderManager.stop ✔️ ✔️