检测 HTML5 媒体捕获 API 支持 [英] Detect HTML5 Media Capture API Support

查看:47
本文介绍了检测 HTML5 媒体捕获 API 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测浏览器是否支持我正在构建的移动网站的 HTML5 Media Capture API?我似乎只能找到检测 getUserMedia() 支持的解决方案.

我希望能够向移动用户展示以下两种情况之一:

  • 用户的浏览器支持 API,因此会显示两个上传按钮,一个用于激活相机,一个用于激活图库.
  • 用户的浏览器不支持 API,所以只显示一个上传按钮,如果他们的浏览器支持接受参数,希望激活图库.

解决方案

用户的浏览器支持该 API,因此会显示两个上传按钮,一个用于激活相机,一个用于激活图库.

没有办法(目前)创建 2 个单独的 HTML 按钮:一个用于(仅)库和一个用于(仅)相机(我在

<块引用>

用户的浏览器不支持API,所以只显示一个上传按钮,如果他们的浏览器支持accept参数,希望激活图库

支持如下:

  • Android 2.2+ 和 iOS6.0+ 支持以上代码
  • Android 3.0+ 支持 capture 并将用户直接带到相机
  • iOS6 到 10 不支持 capture(始终显示提示)
  • 桌面浏览器不支持 HTML 媒体捕获

检测支持恢复到检测上述浏览器.

支持参考:这本 O'Reilly 2013 年的书我的测试

Is there a way to detect whether a browser supports the HTML5 Media Capture API for a mobile website I'm building? I can only seem to find solutions for detecting getUserMedia() support.

I would like to be able to present mobile users one of two scenarios:

  • User's browser supports the API, so two upload buttons are displayed, one activating the camera and one activating the image gallery.
  • User's browser doesn't support the API, so just one upload buttons is displayed, hopefully activating the gallery if their browser supports the accept parameter.

解决方案

User's browser supports the API, so two upload buttons are displayed, one activating the camera and one activating the image gallery.

There's no way (at the moment) to create 2 separate HTML buttons: one for (just) the library & one for (just) the camera ( I've covered all the possible HTML Media Capture options in this article)

Use <input type="file" accept="image/*;"> and you'll be prompted to choose between capturing a photo or selecting an existing one:

User's browser doesn't support the API, so just one upload buttons is displayed, hopefully activating the gallery if their browser supports the accept parameter

Support is as follows:

  • Android 2.2+ and iOS6.0+ support the above code
  • Android 3.0+ supports capture and takes the user straight to the camera
  • iOS6 through 10 do NOT support capture (prompt is always shown)
  • desktop browsers do NOT support HTML Media Capture

Detecting support resumes to detecting the above browsers.

Support reference: this 2013 O'Reilly book and my testing

这篇关于检测 HTML5 媒体捕获 API 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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