Detect browser support for HTML Media Capture

有些话、适合烂在心里 提交于 2020-01-03 07:24:19

问题



How can I detect browser support for HTML Media Capture* ?


The traditional way of testing if an attribute is supported doesn't seem to work on some devices (tested on iPad and Google Nexus):

  var elm = document.createElement(input);
  if (capture in elm) {
    return true;
  } 


There's a test for Modernizr but it doesn't seem to be reliable (it uses the same principle): https://github.com/Modernizr/Modernizr/pull/909

__

(*) More info on HTML Media Capture:

http://www.w3.org/TR/html-media-capture/
http://www.html5rocks.com/en/tutorials/getusermedia/intro/#toc-round1


回答1:


I hope I'm wrong, but it seems we won't be able to make this detection...

The last paper about this HTML MEDIA Capture API (which is different than the Streaming/GetUserMedia API), as been posted last year (2014), and never gone out of the drafts...

This comment from 2012 on a request to implement this feature in Firefox clearly states that :

[T]here is no real need to implement that. It should come for free with Android Intent system. We should just call in intent for ACTION_IMAGE_CAPTURE/ACTION_VIDEO_CAPTURE.

Which means that this feature comes from the OS directly, and that we as developers won't have any way to know if this will be available or not...

So the only way to detect this feature seems to be a UserAgent match against known supporting devices...




回答2:


This form of media capture in browsers is outdated, deprecated, and obsolete. The new standard, getUserMedia, can be detected like so:

function hasGetUserMedia() {
   return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
        navigator.mozGetUserMedia || navigator.msGetUserMedia);
}


来源:https://stackoverflow.com/questions/17070555/detect-browser-support-for-html-media-capture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!