I’m building a web application that captures microphone audio using MediaRecorder and sends it to the backend for processing. Everything works fine on most devices (desktop and mobile), but on some devices, the MediaRecorder.ondataavailable callback is called with an empty Blob (event.data.size === 0), making it impossible to capture usable audio.
Here’s the relevant code:
const recorder = new MediaRecorder(stream, {
mimeType: 'audio/webm;codecs=opus',
})
recorder.ondataavailable = (event) => {
if (event.data.size > 0) {
chunksRef.current.push(event.data)
dataReadyRef.current = true
} else {
console.warn('Empty blob update:', event.data)
}
}
I’m calling recorder.start(1000) to get audio chunks every second. Later I use recorder.stop() to finalize the blob.
On affected devices, I frequently get the warning:
Empty blob update: Blob {size: 0, type: 'audio/webm;codecs=opus'}
My questions:
- Why would
ondataavailablebe triggered with empty blobs? - Are there any known limitations with MediaRecorder across devices/browsers?
- Is there a recommended fallback strategy to ensure we still get usable audio blobs?
Any help or advice would be appreciated.
Timeror other function doing somerequestData()call? (2) Is the sound really unusable if you skip a zero-sized chunk?