I'm making a Visual Campus Map for my Assignment so i'm trying to get the camera to face the environment/back camera instead of myself / front camera
I've tried making a custom reporter block called "Use Back camera" with a Javascript function attached it to it.
Here is the JavaScript Function I used:
let stream = null;
let isExtensionEnabled = false;
function accessBackCamera(videoElement) {
if (!isExtensionEnabled) {
navigator.mediaDevices.getUserMedia({
video: { facingMode: "environment" }
}).then(function(newStream) {
stream = newStream;
videoElement.srcObject = stream;
videoElement.play();
isExtensionEnabled = true;
}).catch(function(error) {
console.error("Failed to access back camera:", error);
});
} else {
if (stream) {
stream.stop();
videoElement.srcObject = null;
}
isExtensionEnabled = false;
}
}
function toggleExtensionState(videoElement) {
accessBackCamera(videoElement);
}
Are there any solutions to fix this issue? Thanks