2012-12-19 100 views
0

我想停止用户访问他们自己的文件系统,即。相机胶卷和移动设备上的视频。迫使他们捕捉现场媒体。这可能吗?如果是的话,我将如何实现这一点?是否有可能撤销JavaScript访问移动文件系统?

+3

我当然希望不可能有一个网页,阻止我访问我的设备。 – David

+0

我假设你在谈论限制某种“”?请说明你想要做什么,也许有一些代码。 – apsillers

回答

2

在支持HTML5的设备上,您可以使用(如果支持)userMedia API。

这是an excellent tutorial为您开始。

基本上,你可以这样做:

<input type="file" accept="image/*;capture=camera"> <!-- Submit a new photo --> 
<input type="file" accept="video/*;capture=camcorder"> <!-- Submit a new video --> 
<input type="file" accept="audio/*;capture=microphone"> <!-- Submit a new audio track using the microphone --> 

就像我说的,这只会如果支持工作。目前,iOS6下的设备均为部分,支持userMedia API。

如果您的设备支持API,但不支持accept="image/*;capture=camera" ...等,您可以编写自己的按钮来完成相同的操作。

<input type="button" id="newStream" value="Click me!"> 
<script> 
    // Following code adapted from the tutorial, not tested 
    document.getElementById('newStream').addEventListener('click', function(event){ 
     // Not showing vendor prefixes or code that works cross-browser. 
     navigator.getUserMedia({video: true}, function(stream){ 
      // Do something with stream or window.URL.createObjectURL(stream); 
      alert('Success!'); 
     }, function(){ alert('Failed!'); }); 
    }); 
</script> 
+0

这看起来非常合适,但是你在哪里获得'; capture = camera'语法?我所能找到的只是[W3C Media Capture API]中的布尔型capture属性(http://www.w3.org/TR/html-media-capture/#dfn-capture-1)。 – apsillers

+0

查看我提供的链接:http://www.html5rocks.com/en/tutorials/getusermedia/intro/ –

+0

感谢您的支持。我试过这些。我正在专门研究iOS6和Android,因此“捕获”和getUserMedia API尚未完成。我希望用户只能在特定位置提交视频和照片。我最初的想法是不允许站点访问文件系统,而不是一起撤销访问。我也想过看媒体的地理位置元数据,但不知道最佳路线是什么。也想过访问uiimagepickercontroller,但这从web应用程序似乎是不可能的。 – KLJ3