# Can't switch preview video when using \*\*navigator.mediaDevices.getUserMedia\*\* before

**URL:** <https://devforum.zoom.us/t/cant-switch-preview-video-when-using-navigator-mediadevices-getusermedia-before/114048>\
**Category:** Web\
**Tags:** video-sdk\
**Created:** [July 20, 2024, 4:23am UTC](https://devforum.zoom.us/t/cant-switch-preview-video-when-using-navigator-mediadevices-getusermedia-before/114048 "2024-07-20T04:23:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunt](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dunt/32/60077_2.png) [@dunt](https://devforum.zoom.us/u/dunt)\
**Post date:** [July 20, 2024, 4:23am UTC](https://devforum.zoom.us/t/cant-switch-preview-video-when-using-navigator-mediadevices-getusermedia-before/114048/1 "2024-07-20T04:23:57Z")

</div>

**Description**  
Can’t switch preview video when using **navigator.mediaDevices.getUserMedia** before.

**Browser Console Error**

 ![Screenshot 2024-07-20 at 11.06.25](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/f/4/f40fe4576528daf4f66e4fcd7330c157421f9f30.png)

**Which Web Video SDK version?**  
video-sdk version: 1.11.6

**Video SDK Code Snippets**  
I have an issue: Camera will be stoped when screen device is locked so my solution is using **navigator.mediaDevices.getUserMedia** so that we got another problem that can’t switch preview camera

switch preview camera func:  
 ![Screenshot 2024-07-20 at 11.11.55](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/e/5/e5d85714f6a91ffbe8bbb29a12f8b7129d5d4157.png)

when we start preview video, we also create **video dom** :

 ![Screenshot 2024-07-20 at 11.14.01](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/d/6d4500978ee7b762d394ae95547b870e18d06388.png)

base on this website:

> **[MediaDevices - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices)**
>
> The MediaDevices interface of the Media Capture and Streams API provides access to connected media input devices like cameras and microphones, as well as screen sharing. In essence, it lets you obtain access to any hardware source of media data.

My question is:

1. I need your help to fix this problem.
2. If we can’t use **navigator.mediaDevices.getUserMedia** to solve my issue above so if is there any solution for this ?.

**To Reproduce(If applicable)**  
Steps to reproduce the behavior:

1. Preview screen
2. Switch camera

**Screenshots**

 ![Screenshot 2024-07-20 at 11.19.09](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/b/c/bc0ec57e7ee3d20f5e27a6c9717726f10c425dab.png)

**Troubleshooting Routes**  
The troubleshooting attempt types you’ve already exhausted, including testing with the appropriate sample app (found on [Zoom · GitHub](https://github.com/zoom)).

**Device (please complete the following information):**

- Device: Mac
- OS: Ventura 13.3.1
- Browser: Chrome
- Browser: Version 126.0.6478.183 (Official Build) (arm64)

**other**  
comment line 773 → 778 will not get error.

 ![Screenshot 2024-07-20 at 11.23.07](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/0/c/0c38b770e307ebc202d7d71893dd70a7959b6115.png)

Hope see your answer soon.  
Thanks

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 7, 2024, 1:13pm UTC](https://devforum.zoom.us/t/cant-switch-preview-video-when-using-navigator-mediadevices-getusermedia-before/114048/2 "2024-08-07T13:13:31Z")

</div>

Hey @dunt

Sorry for the late reply.

> Camera will be stoped when screen device is locked so my solution is using **navigator.mediaDevices.getUserMedia**

In Video SDK Web, we provide an option named `stayAwake` in the `client.init` method. It may meet your requirements.

> **[InitOptions | Zoom Video SDK for Web - 1.12.0](https://marketplacefront.zoom.us/sdk/custom/web/interfaces/InitOptions.html#stayAwake)**
>
> Documentation for Zoom Video SDK for Web - 1.12.0

> we got another problem that can’t switch preview camera

Since the camera is being used to prevent screen lock, it cannot be used for the preview.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [September 6, 2024, 11:14pm UTC](https://devforum.zoom.us/t/cant-switch-preview-video-when-using-navigator-mediadevices-getusermedia-before/114048/3 "2024-09-06T23:14:10Z")

</div>

Closed on September 6, 2024, 11:14pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
