I know this is a common question, but for some reason, there are several answers (which confuses me)
tl;dr I am trying to set a button that let you record yourself for up to 10 seconds (you can press stop if you want to stop recording before) and then let you play it.
What I have tried till now :
I know there is the library getUserMedia
, and I have (tried) created a MediaStream
.
I get confused when it comes to the Recording itself and the.Start() and Stop()
here is my code for getting the user`s permission to access the microphone :
const getmiceacesses = function () {
const stream = navigator.mediaDevices
.getUserMedia({ audio: true })
.then(function (stream) {const mediaRecorder = new MediaRecorder(stream);
const audioChunks = [];
mediaRecorder.addEventListener("dataavailable", (event) => {
audioChunks.push(event.data);
});
});};
const recording = document.querySelector(`.recorder`);
recording.addEventListener(`click`, getmiceacesses);
Thank you guys!