I am trying to record screen, audio and save it in local. I could record the video and save the file but I couldn't hear the audio in the saved file. Please help me out.
Code
async function recordScreen() {
const video = document.createElement("video");
const stream = await navigator.mediaDevices.getDisplayMedia({
video: { mediaSource: "screen" },
audio: true
});
navigator.mediaDevices.getUserMedia({audio:true}).then((mic) => {
stream.addTrack(mic.getTracks()[0]);
});
const recorder = new MediaRecorder(stream);
const chunks = [];
recorder.ondataavailable = e => chunks.push(e.data);
recorder.start();
recorder.onstop = e => {
const completeBlob = new Blob(chunks, { type: 'video/webm;codecs=vp9' });
video.src = URL.createObjectURL(completeBlob);
let file = new File([completeBlob], `${user}-${new Date()}-record.webm`);
saveAs(file);
};
}