停止/关闭由navigator.getUserMedia打开的网络摄像头 [英] Stop/Close webcam which is opened by navigator.getUserMedia

查看:2355
本文介绍了停止/关闭由navigator.getUserMedia打开的网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下JavaScript代码打开了网络摄像机: navigator.getUserMedia



有没有JavaScript代码停止或关闭摄像头?

解决方案

编辑

由于此答案最初发布,因此浏览器API已更改。
.stop()在传递给回调的流上不再可用。
开发人员必须访问构成流(音频或视频)的曲目并分别停止它们。



更多信息: https://developers.google.com/web/更新/ 2015/07 / mediastream-deprecations?hl = en#stop-ended-and-active



示例(来自上面的链接):



  var track = stream.getTracks()[0]; //如果只有一个媒体轨道// ... track.stop();  



浏览器支持可能会有所不同。

原始答案

navigator.getUserMedia 为成功回调提供了一个流,您可以在该流上调用 .stop()来停止录音(至少在Chrome中,似乎FF不喜欢它)


I opened a webcam by using the following JavaScript code: navigator.getUserMedia

Is there any JavaScript code to stop or close the webcam? Thanks everyone.

解决方案

EDIT

Since this answer has been originally posted the browser API has changed. .stop() is no longer available on the stream that gets passed to the callback. The developer will have to access the tracks that make up the stream (audio or video) and stop each of them individually.

More info here: https://developers.google.com/web/updates/2015/07/mediastream-deprecations?hl=en#stop-ended-and-active

Example (from the link above):

var track = stream.getTracks()[0];  // if only one media track
// ...
track.stop();

Browser support may differ.

Original answer

navigator.getUserMedia provides you with a stream in the success callback, you can call .stop() on that stream to stop the recording (at least in Chrome, seems FF doesn't like it)

这篇关于停止/关闭由navigator.getUserMedia打开的网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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