# DEVICE\_ACCESS\_DENIED switching camera

**URL:** <https://openvidu.discourse.group/t/device-access-denied-switching-camera/439>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [April 9, 2020, 10:42am UTC](https://openvidu.discourse.group/t/device-access-denied-switching-camera/439 "2020-04-09T10:42:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blazeag](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@blazeag](https://openvidu.discourse.group/u/blazeag)\
**Post date:** [April 9, 2020, 10:42am UTC](https://openvidu.discourse.group/t/device-access-denied-switching-camera/439/1 "2020-04-09T10:42:06Z")

</div>

Hi,

I’m using OpenVidu browser. I found a strange behaviour on a Samsung Galaxy Tab A (2016) using Chrome (firstly tried with v74, but it didn’t solve updating to v80).

When I open the page, the camera permission correctly pops-up. I grant permission, and everything works fine. But switching to back camera (with Publisher.replaceTrack), OpenVidu throws a “DEVICE\_ACCESS\_DENIED” error. This doesn’t happen in other devices I tried (Samsung Galaxy A70, Samsung Galaxy A50, Google Nexus 5x, iPhone 8, Huawei P30 lite).

So, my question is: is there a way to force the browser to pop-up a new permission dialog for the other camera?

---

<div class="post-metadata">

**Author:** ![micael.gallego](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/micael.gallego/32/2_2.png) [@micael.gallego](https://openvidu.discourse.group/u/micael.gallego)\
**Post date:** [April 10, 2020, 12:44am UTC](https://openvidu.discourse.group/t/device-access-denied-switching-camera/439/2 "2020-04-10T00:44:53Z")

</div>

I don’t know. It seems a problem with the combination between browser and device operating system.

Maybe you can play with native WebRTC API to get access to the camera and then use OpenVidu methods.

---

<div class="post-metadata">

**Author:** ![blazeag](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@blazeag](https://openvidu.discourse.group/u/blazeag)\
**Post date:** [April 10, 2020, 8:12am UTC](https://openvidu.discourse.group/t/device-access-denied-switching-camera/439/3 "2020-04-10T08:12:37Z")

</div>

I solved catching the error and using unpublish/publish instead of replaceTrack when the error occurs, and it now works with all browsers, ~~IE6~~ Safari 12 included.

But I will give a try to the native WebRTC API too. I let you know if I’m lucky, thank you very much @micael.gallego .

Here is the pseudo-code:

```
var video_source = deviceId;

OV.getUserMedia({audioSource: false, videoSource: video_source})
.then(function (media)
{
    var new_camera = media.getVideoTracks()[0];
    publisher.replaceTrack(new_camera);
})
.catch(function (error)
{
    switch (error.name)
    {
        case 'DEVICE_ACCESS_DENIED':
            console.log('Access denied, trying republishing');

            session.unpublish(publisher);
            publisher = OV.initPublisher(undefined, {videoSource: video_source});
            publisher.addVideoElement(document.getElementById('video-element'));
            break;

        default:
            console.log(error);
            break;
    }
});
```
