** Video SDK 1.11.5 for web app (React) **
Description
We’ve installed the latest 1.11.5 Video SDK (for web) and found out that the switchCamera
function for iPhone doesn’t work after the user has stopped and restarted the video.
How To Reproduce
await mediaStream.startVideo();
// works
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
await mediaStream.switchCamera(MobileVideoFacingMode.User);
await mediaStream.stopVideo();
await mediaStream.startVideo();
// doesn't works
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
The camera is still the front-facing camera. Doesn’t matter how many times I switch back and forth, it remains showing the front-facing camera.
The same behavior works well in version 1.11.0. Seems like a regression bug.
Hey @jkpchang
Thanks for your feedback.
We can reproduce this issue and will fix it soon.
Thanks
Vic
this happened to me as well, waiting for the solution
thanks
Hey @dareveggen @jkpchang
Thanks for your feedback.
A workaround for it is to specify the cameraId
parameter on stream.startVideo
method so that stream.switchCamera
won’t be affected by this issue.
await mediaStream.startVideo({cameraId:MobileVideoFacingMode.User});
// works
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
await mediaStream.switchCamera(MobileVideoFacingMode.User);
await mediaStream.stopVideo();
await mediaStream.startVideo({cameraId:MobileVideoFacingMode.User}); // Explicitly set the camera ID.
// works
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
Thanks
Vic
Add debugging statements to log the current state of the camera and any errors returned by the SDK functions. For example:
await mediaStream.startVideo();
console.log(‘Video started’);
// Initial switch works
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
console.log(‘Switched to environment camera’);
await mediaStream.switchCamera(MobileVideoFacingMode.User);
console.log(‘Switched to user camera’);
await mediaStream.stopVideo();
console.log(‘Video stopped’);
await mediaStream.startVideo();
console.log(‘Video started again’);
// Subsequent switch fails
try {
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
console.log(‘Switched to environment camera’);
} catch (error) {
console.error(‘Error switching to environment camera:’, error);
}
Workaround
As a temporary workaround, you might want to reinitialize the media stream completely after restarting the video. This can be more resource-intensive, but it could bypass the issue until a permanent fix is provided.
Reinitialize Media Stream Example
async function reinitializeMediaStream() {
await mediaStream.stopVideo();
await mediaStream.stop(); // Completely stop the media stream
// Reinitialize the media stream
await mediaStream.startVideo();
console.log('Reinitialized video stream');
try {
await mediaStream.switchCamera(MobileVideoFacingMode.Environment);
console.log('Switched to environment camera');
} catch (error) {
console.error('Error switching to environment camera:', error);
}
}
// Usage
await reinitializeMediaStream();
For more information, visit: [Drive Zone](https://drivezoneapk.com/)