最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Access camera or webcam without webRTC - Stack Overflow

programmeradmin1浏览0评论

In my website, it needs to access camera or webcam. But webRTC is not supported yet on ios webview based on (please cmiiw). So, I'm trying to find a way to access it without webRTC. Is there any?

  1. And is this following code, a part of utilizing webRTC? Because the console.log shows up on ios webview

    function hasGetUserMedia() {
      return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || 
        navigator.mozGetUserMedia || navigator.msGetUserMedia);
    }
    
    //then, somewhere in the code
    if (!hasGetUserMedia()) {           
      console.log( "webRTC is not supported in your browser" );//it shows up on ios webview              
    }
    
    //other code
    navigator.mediaDevices.getUserMedia({
     audio: false, //no audio
     video: {deviceId: {exact: videoSource.camera_id} }
    })
    
  2. If yes, so what's the workaround which not using webRTC, and can be run on android webview, ios webview, and web browsers?

In my website, it needs to access camera or webcam. But webRTC is not supported yet on ios webview based on https://forums.developer.apple./thread/88052 (please cmiiw). So, I'm trying to find a way to access it without webRTC. Is there any?

  1. And is this following code, a part of utilizing webRTC? Because the console.log shows up on ios webview

    function hasGetUserMedia() {
      return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || 
        navigator.mozGetUserMedia || navigator.msGetUserMedia);
    }
    
    //then, somewhere in the code
    if (!hasGetUserMedia()) {           
      console.log( "webRTC is not supported in your browser" );//it shows up on ios webview              
    }
    
    //other code
    navigator.mediaDevices.getUserMedia({
     audio: false, //no audio
     video: {deviceId: {exact: videoSource.camera_id} }
    })
    
  2. If yes, so what's the workaround which not using webRTC, and can be run on android webview, ios webview, and web browsers?

Share Improve this question edited Jan 23, 2019 at 6:15 Alvin Theodora asked Jan 23, 2019 at 4:13 Alvin TheodoraAlvin Theodora 9461 gold badge11 silver badges18 bronze badges 3
  • 1 The code listed above is not part of webRTC. You can very well use that with webview. – CuriousMind Commented Jan 23, 2019 at 4:19
  • I have edited the code, are you sure it's not? Because the console.log shows up. And the camera device is not accessed – Alvin Theodora Commented Jan 23, 2019 at 4:26
  • 2 iOS WebViews don’t support getUserMedia. WebRTC is pretty irrelevant to that. So, no, the one method to access webcam streams does not exist. – deceze Commented Jan 23, 2019 at 6:41
Add a ment  | 

1 Answer 1

Reset to default 9

2021 Edit:

We now have access to getUserMedia on iOS WebViews!


The Good News:

As of iOS 14.3, iOS now allows access to getUserMedia in a WKWebView

Whenever I have questions about browser features like this, I find it very helpful to check out caniuse.. In this case, there is a note on the entry for Safari & Chrome for iOS

Before iOS 14.3 getUserMedia returned no video input devices in UIWebView or WKWebView, but only directly in Safari

The Old News:

Prior to 2021, we could not access getUserMedia on iOS outside of Safari. So back then, a workaround was to build a website and direct iOS users to visit the site in Safari instead of making a native app for iOS.

The Other News:

getUserMedia controls access to a user's camera and microphone, whereas WebRTC helps you send that audio/video to another client, like in a video chat. Here you're stuck on getting the video in the first place so you don't need to worry about WebRTC yet, but when you do, I remend you check out This article that helped me.

And if you want to test getUserMedia or WebRTC functions yourself, try using These provided samples, so that you can be sure that it is not the fault of your own code :)

发布评论

评论列表(0)

  1. 暂无评论