chrisguttandin/extendable-media-recorder

Failed to initialize native MediaRecorder the type provided (audio/wav)

Closed this issue · 5 comments

Followed the example in the docs, throws an exception with Failed to initialize native MediaRecorder the type provided (audio/wav).
Screenshot 2021-02-20 at 13 05 24

Hi @JoshuaeKaiser,

now that I re-read the readme again I think it's a bit misleading. The import from the first snippet should have been included in the second snippet as well.

That's the full version:

import { MediaRecorder, register } from 'extendable-media-recorder';
import { connect } from 'extendable-media-recorder-wav-encoder';

await register(await connect());

const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const mediaRecoder = new MediaRecorder(stream, { mimeType: 'audio/wav' });

Does that solve your problem?

Hi @chrisguttandin thanks for the quick response. Yes that makes sense, however a second issue arrises. An unhandled rejection having to do with your custom encoder alredy being registered.

"Unhandled Rejection (Error): There is already an encoder stored which handles exactly the same mime types."

For context im using your Lib inside a react App. I realise react reactivity might be instansiating the constructor multiple times as the component reloads, but I dont think that can be the case as Im accounting for it by only calling the constructor if the variable it is to be stored in is null.

Screenshot 2021-02-21 at 12 07 35

The register() function is probably throwing that error. It complains when there is already a codec registered for the same mime type. You could solve this by creating a global promise somewhere.

const REGISTER_AND_CONNECT = connect().then(register);

You could then use Promise.all() to make sure the codec is available when calling the MediaRecorder constructor.

useEffect(async () => {
    Promise.all([
        REGISTER_AND_CONNECT,
        navigator.mediaDevices.getUserMedia({ audio: true })
    ])
    .then(([ , mediaStream]) => {
        // ...
    })
})

I hope this helps.

@chrisguttandin your a star my friend, been strugling for 2 days with this encoding issue. Thanks very much for the help, solved my issue and it outputs a perfect .wav, Great library!

I'm happy to hear that. I added the missing import statement to the readme.