在没有webRTC的情况下访问摄像头或摄像头 [英] Access camera or webcam without webRTC

查看:304
本文介绍了在没有webRTC的情况下访问摄像头或摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,它需要访问摄像头或网络摄像头.但是基于 https://forums.developer.apple.com的ios webview尚不支持webRTC /thread/88052 (请cmiiw).因此,我试图找到一种无需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). So, I'm trying to find a way to access it without webRTC. Is there any?

  1. 以下代码是利用webRTC的一部分吗?因为console.log显示在ios webview上

  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} }
})

  • 如果是,那么不使用webRTC并可以在android webview,ios webview和Web浏览器上运行的解决方法是什么?

  • If yes, so what's the workaround which not using webRTC, and can be run on android webview, ios webview, and web browsers?

    推荐答案

    坏消息:

    iOS WebViews不支持getUserMedia,这意味着您将完全无法访问用户的相机.截至2019年1月,没有任何解决方法.我还在等待iOS WebViews支持getUserMedia,所以我感到您很痛苦.

    The Bad News:

    iOS WebViews don't support getUserMedia, which means you won't be able to access the user's camera at all. There is no workaround as of Jan 2019. I'm also waiting for getUserMedia to be supported on iOS WebViews, so I feel your pain.

    每当我对这样的浏览器功能有疑问时,我发现检查 caniuse.com 很有帮助.在这种情况下,它表明Safari& Chrome for iOS(于2018年9月发布)支持getUserMedia,但它...

    Whenever I have questions about browser features like this, I find it very helpful to check out caniuse.com. In this case, it shows that the latest version of Safari & Chrome for iOS (released Sep 2018) supports getUserMedia, but that it...

    在独立运行(已安装")的PWA中不起作用,getUserMediaUIWebViewWKWebView中不返回任何视频输入设备,而仅在Safari中直接返回.

    Does not work in standalone running ("installed") PWAs, getUserMedia returns no video input devices in UIWebView or WKWebView, but only directly in Safari.

    好消息:

    如果您只是想让您的网站在iOS设备上运行,那么您很幸运. 除非您正在为App Store制作应用程序,否则不需要使用WebView . getUserMedia将适用于在iOS上使用Safari浏览您的网站的用户!而且,如果有帮助,您的用户甚至可以将指向您网站的链接添加到iOS的主屏幕上,这使其看起来非常像一个应用程序.

    The Good News:

    If you are just interested in having your website work on iOS devices, then you are in luck. You don't need to use a WebView unless you are making an app for the App Store. getUserMedia will work for users who visit your website using Safari on iOS! And if it helps, your users can even add a link to your website onto their home screen on iOS, which makes it seem very much like an app.

    getUserMedia控制对用户相机和麦克风的访问,而WebRTC可帮助您将音频/视频发送到另一个客户端,例如在视频聊天中.在这里,您首先要获取视频,因此不必担心WebRTC,但是当您这样做时,建议您查看

    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 recommend you check out This article that helped me.

    如果您想自己测试getUserMedia或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 :)

    这篇关于在没有webRTC的情况下访问摄像头或摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆