简体   繁体   English

在没有 webRTC 的情况下访问摄像头或网络摄像头

[英]Access camera or webcam without webRTC

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.com/thread/88052 (please cmiiw).但是基于https://forums.developer.apple.com/thread/88052 (请cmiiw)的ios webview尚不支持webRTC。 So, I'm trying to find a way to access it without webRTC.因此,我试图找到一种无需 webRTC 即可访问它的方法。 Is there any?有没有?

  1. And is this following code, a part of utilizing webRTC?以下代码是利用 webRTC 的一部分吗? Because the console.log shows up on ios webview因为 console.log 显示在 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?如果是,那么不使用 webRTC 并且可以在 android webview、ios webview 和 web 浏览器上运行的解决方法是什么?

2021 Edit: 2021 编辑:

We now have access to getUserMedia on iOS WebViews!我们现在可以在 iOS WebViews 上访问getUserMedia


The Good News:好消息:

As of iOS 14.3, iOS now allows access to getUserMedia in a WKWebView从 iOS 14.3 开始,iOS 现在允许访问WKWebView getUserMedia

Whenever I have questions about browser features like this, I find it very helpful to check out caniuse.com .每当我对这样的浏览器功能有疑问时,我发现查看caniuse.com非常有帮助。 In this case, there is a note on the entry for Safari & Chrome for iOS在这种情况下,iOS 版 Safari 和 Chrome 的条目上有一个注释

Before iOS 14.3 getUserMedia returned no video input devices in UIWebView or WKWebView , but only directly in Safari在 iOS 14.3 之前getUserMediaUIWebViewWKWebView没有返回视频输入设备,而是直接在 Safari 中返回

The Old News:旧新闻:

Prior to 2021, we could not access getUserMedia on iOS outside of Safari.在 2021 年之前,我们无法在 Safari 之外的 iOS 上访问getUserMedia 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.因此,当时的解决方法是建立一个网站并引导 iOS 用户在 Safari 中访问该网站,而不是为 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. getUserMedia控制对用户摄像头和麦克风的访问,而 WebRTC 可帮助您将该音频/视频发送到另一个客户端,例如在视频聊天中。 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 recommend you check out This article that helped me.在这里,您首先坚持获取视频,因此您无需担心 WebRTC,但是当您这样做时,我建议您查看这篇对我有帮助的文章

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 :)如果你想自己测试getUserMedia或 WebRTC 功能,请尝试使用这些提供的示例,这样你就可以确定这不是你自己代码的错:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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