Skip to content

Events ​

All events are props on WaveformRecorderView. Payload types are in the API reference.

EventPayloadWhen
onStateChange{ state, durationMs }On every state change.
onMeter{ amplitude, peak, db }meterUpdatesPerSecond times per second while recording.
onCompletesee belowOnce the final file is written after stop() or an automatic stop.
onMaxDurationReachednoneWhen maxDurationMs is reached, right before the automatic stop.
onPermissionDeniednoneWhen start() cannot get microphone permission.
onError{ message, code? }Warnings and failures, see error codes.
onSeek{ positionMs }In preview, at the end of a scrub and after seekPreview().
onPlaybackTimeUpdate{ positionMs, durationMs }About 30 times per second while preview audio plays.
onSlideProgress{ cancelProgress, lockProgress }While the user drags on the view during recording.
onSlideCancelnoneOnce per drag, when the cancel threshold is crossed.
onSlideLocknoneOnce per drag, when the lock threshold is crossed.
onSilenceDetected{ durationMs }Once per quiet stretch, see Silence detection.
onPcmChunk{ chunk, sampleRate, channels, bytesPerSample, timestampMs }About every pcmChunkMs while PCM streaming is on, see PCM stream.

onStateChange ​

state is one of 'idle', 'recording', 'paused', 'preview', 'stopped' or 'error'. durationMs is the recorded time so far, without the time spent paused. See Segments, pause and preview for the transitions.

onMeter ​

FieldMeaning
amplitudeCurrent level in [0, 1], the value used for the newest bar.
peakHighest amplitude so far in this session.
dbCurrent level in dBFS. 0 is full scale, quieter is more negative.

The two platforms measure the level differently, so the same sound gives different numbers. iOS reports the average power over the last tick and maps it as 10^(db / 20), with anything at or below -60 dB shown as 0. Android reports the peak since the last tick and maps it as the square root of the linear peak. Do not compare raw values across platforms.

onComplete ​

FieldTypeMeaning
uristringfile:// URI of the recording.
durationMsnumberRecorded duration, summed over all segments.
formatstringThe output.format you asked for.
mimeTypestringMIME type, see Formats.
sizeBytesnumberFile size.
sampleRatenumberSample rate in Hz.
channelsnumberChannel count.
samplesnumber[]64 values in [0, 1] for a chat bubble, see Export.
peakAmplitudenumberHighest meter amplitude of the session.

onComplete does not fire when nothing was recorded, when cancel() is called, or when minDurationMs discards the recording.

Error codes ​

onError is used for real failures and for warnings about calls that were ignored. Check code:

CodeMeaning
startThe recorder could not start. The state becomes 'error'.
sessioniOS could not configure the audio session. The state becomes 'error'.
resumeResuming after pause() failed. The state becomes 'error'.
media-recorderAndroid: MediaRecorder reported an error while recording.
min-durationstop() was called below minDurationMs. The recording was discarded.
preview-disabledenterPreview() was called with enablePreview={false}.
continue-disabledresume() was called in preview with enableContinueRecording={false}.
preview-snapshotPreview could not be prepared, for example because nothing was recorded yet.
preview-loadThe preview player could not load the audio.
concatJoining segments failed. onComplete still fires with the first segment so the audio is not lost.
format-unsupportedopus was requested on Android below API 29. The engine records AAC instead.
pcm-streamiOS: PCM streaming could not open the WAV file.
background-capabilityiOS: backgroundRecording is on but audio is missing from UIBackgroundModes. Fires once.

From 'error', calling start() begins a new session.

Released under the MIT License.