检查是否通过`getDisplayMedia`捕获浏览器/平台支持的屏幕 [英] Check if browser/platform support screen capturing via `getDisplayMedia`

查看:1174
本文介绍了检查是否通过`getDisplayMedia`捕获浏览器/平台支持的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以通过navigator.mediaDevices.getDisplayMedia()请求将媒体流发送到屏幕或窗口.但是,这立即提示用户决定要使用哪种捕获.我需要检查浏览器/平台是否支持屏幕捕获.

We can request a media stream to a screen or windows via navigator.mediaDevices.getDisplayMedia(). However, this immediately prompts the user to decide which kind of capturing to use. I need to check if the browser/platform even support screen capturing.

当然可以检查'getDisplayMedia' in navigator.mediaDevices,但这只是告诉我们浏览器是否支持该API.特别是,在FF和Android上的Chrome上,已定义了API,并且可以调用getDisplayMedia(),但始终会立即返回NotAllowedError错误(这是可以预期的:

Of course, it is possible to check for 'getDisplayMedia' in navigator.mediaDevices, but this just tells us if the API is supported by the browser. In particular, on FF and Chrome on Android, the API is defined and I can call getDisplayMedia(), but it always immediately returns a NotAllowedError error (which is to be expected: according to caniuse, the mobile browsers do not yet support getDisplayMedia.)

接下来,我尝试检查navigator.mediaDevices.getSupportedConstraints().但是,我的移动FF返回与桌面FF完全相同的对象.特别地,在两种情况下,navigator.mediaDevices.getSupportedConstraints().mediaSource都是true.最后,navigator.mediaDevices.enumerateDevices()返回的数据也无济于事.我只能得到无法以任何方式解释的设备和组ID(对吗?).

Next, I tried checking navigator.mediaDevices.getSupportedConstraints(). However, my mobile FF returns the exact same object as my desktop FF. In particular, navigator.mediaDevices.getSupportedConstraints().mediaSource is true in both cases. Finally, the data returned by navigator.mediaDevices.enumerateDevices() does not help me either. I only get a device and group ID which I cannot interpret in any way (right?).

是否可以预先检测是否支持通过getDisplayMedia进行的屏幕捕获?

Is it possible to detect whether or not screen capture via getDisplayMedia is supported beforehand?

(注意:此问题与解答; A 看起来很相似,但大约是getUserMedia,已经很老了

(Note: this Q&A seems fairly similar, but is about getUserMedia and is already quite old)

推荐答案

不幸的是,没有直接的方法来检测 getDisplayMedia 在这些浏览器上是否可以正常工作.

Unfortunately, there's no direct way to feature-detect whether getDisplayMedia will work on those browsers.

您今天可以做的只是浏览器嗅探器UA字符串,以检测您不在缺少支持的移动设备上.¹

All you can do today is browser-sniff the UA string to detect you're not on mobile, where support is lacking.¹

我已根据您的要求提交了问题问题,以查看 getDisplayMedia 在不支持时是否最好留在undefined上.

I've filed an issue on the spec based on your question, to see if getDisplayMedia is better left undefined when unsupported.

1. caniuse 声称Opera Mobile支持,但是当我

1. caniuse claims Opera Mobile has support, but this appears not so when I test it.

这篇关于检查是否通过`getDisplayMedia`捕获浏览器/平台支持的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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