简体   繁体   中英

navigator.mozGetUserMedia has been replaced by navigator.mediaDevices.getUserMedia

I have error on barcode scanner plugin. It's working in chrome but not working in Firefox. I am getting error in console :

navigator.mozGetUserMedia has been replaced by navigator.mediaDevices.getUserMedia

My demo url:https://rawgit.com/saravanasksp/myproject/master/src/index.html

Anyone please let me know about the issue.

You should be able to just change your function call. The constraint objects passed to each are the same the main difference is the navigator.mozGetUserMedia relies on callbacks. The new navigator.mediaDevices.getUserMedia returns a Promise.

So where you had

navigator.mozGetUserMedia(constraints, 
   stream => handleStream(stream), 
    err => handleError(err));

You now have

navigator.mediaDevices.getUserMedia(constraints)
.then(stream => {handleStream(stream)})
.catch(err => {handleError(err)}

Sorry I should have added links

https://developers.google.com/web/updates/2015/10/media-devices https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM