Reputation: 21
I am trying to call recorder.start(); in my javascript but the console error shows recorder.start() is not a function. What am I doing wrong ?
const recordAudio=async function() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const mediaRecorder = new MediaRecorder(stream);
const audioChunks = [];
mediaRecorder.addEventListener("dataavailable", event => {
audioChunks.push(event.data);
});
let start = function(){ mediaRecorder.start()};
};
const handleAction=function() {
const recorder = recordAudio();
const actionButton = document.getElementById('action');
actionButton.disabled = true;
recorder.start();
}
Upvotes: 0
Views: 116
Reputation: 1
What you get is a Promise instance not a function instance, so that the start() is not exist.
Maybe you can just call start() in recordAudio(), it will execute when your stream is prepared.
Upvotes: 0
Reputation: 36954
Your recordAudio
function returns Promise<void>
.
Return mediaRecorder
instead, or return an object that contain that start
method
return { start }
and then you can get the value of the instance with const recorder = await recordAudio();
Upvotes: 1