let defaultsOpts = { audio: true, video: true }
function capture(){
// Step - 1.Checking Device Support
if (
"mediaDevices" in navigator &&
"getUserMedia" in navigator.mediaDevices
) {
defaultsOpts.video = { facingMode: state?.shouldFaceUser ? 'user' : 'environment',
width: window.screen.height, height: window.screen.width,
}
// Requesting user permission
navigator.mediaDevices
.getUserMedia(defaultsOpts)
.then((stream) => {
// video element
window.videoElement = document.getElementById("preview");
window.stream = stream;
window.track = window?.stream?.getVideoTracks()[0];
if('srcObject' in window.videoElement){
window.videoElement.srcObject = window.stream;
}else{
// older version
window.videoElement.src = window.URL.createObjectURL(window.stream);
}
window.videoElement.captureStream =
window.videoElement.captureStream || window.videoElement.mozCaptureStream;
return new Promise(resolve => window.videoElement.onplaying = resolve)
})
.catch((log) => {
alert("User Denied accessing camera & audio device", log);
});
}else{
alert("your browser does not support camera")
}
}
capture();
here inside capture function, video stream gets started and it records the audio through default microphone.but i want to play and record user uploaded file(mp3 song) and play that song along with video after recording the stream.