I’m displaying my camera’s feed on a video tag and it works well for the most part. On mobile, I have added logic to swap between the front and rear cameras, which functions correctly. However, I’m facing two issues:
- Latency: The time for the video to appear can be quite long, especially when switching between cameras.
- Low Power Mode: When the device is in Low Power Mode, the video feed sometimes doesn’t appear at all.
async initCamera() {
try {
= await navigator.mediaDevices.getUserMedia({
video: { facingMode: this.currentFacingMode }, // "user" per default
audio: false,
});
// Set the new stream to the video element and start playing it
this.video.srcObject = ;
await this.video.play();
} catch (err) {
console.error(`An error occurred: ${err}`);
}
}
toggleCamera() {
this.currentFacingMode = this.currentFacingMode === "user" ? "environment" : "user";
this.initCamera();
}