Skip to content Skip to sidebar Skip to footer

Mediarecorder Ondataavailable Work Successfully Once

MediaRecorder ondataavailable work successful once. I need to get blob, get it base64, send to my server, decode this base64 to audio blob. This is very strange. For example, outpu

Solution 1:

I am not sure what is the problem you try to highlight, but:

The dataavailable event's data property contains only a chunk of the whole data that has been recorded. For instance, only the first chunk will contain the metadata needed for the final recorded media.

It is then expected that you will merge all these chunks together at the time you will export them.

And this should be done only once, at the MediaRecorder.stop event.

const chunks = []; // store all the chunks in an array
recorder.ondataavailable = e => chunks.push(e.data);
// merge the chunks in a single Blob here
recoder.onstop = e =>export_media(newBlob(chunks));

Post a Comment for "Mediarecorder Ondataavailable Work Successfully Once"