使用getUserMedia和RTCPeerConnection Chrome 25停止/关闭网络摄像头 [英] Stop/Close webcam using getUserMedia and RTCPeerConnection Chrome 25

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

问题描述

我使用getUserMedia和RTCPeerConnection成功使用getUserMedia和RTCPeerConnection将音频从网页连接到另一方,但我无法使用API​​停止Chrome标签中正在使用媒体的红色闪烁指示图标在那个页面上。我的问题基本上是停止/关闭网络摄像头的重复通过navigator.getUserMedia ,除了那里的分辨率不起作用。如果我的页面只使用没有远程媒体的getUserMedia(无对等),则停止摄像机会关闭闪烁的标签指示。添加远程流似乎是一个问题。这是我目前得到的关闭代码:

I'm on Chrome 25 successfully using getUserMedia and RTCPeerConnection to connect audio from a web page to another party, but I'm unable to get the API to stop the red blinking indication icon in the Chrome tab that media is being used on that page. My question is essentially a duplicate of Stop/Close webcam which is opened by navigator.getUserMedia except that the resolution there isn't working. If I have a page that just uses getUserMedia with no remote media (no peer), then stopping the camera turns off the blinking tab indicator. Adding remote streams seems to be a/the issue. Here's what I've currently got for my "close" code:

if (localStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(localStream);
    }
    if (localStream.stop) {
        localStream.stop();
    }
    localStream.onended = null;
    localStream = null;
}
if (localElement) {
    localElement.onerror = null;
    localElement.pause();
    localElement.src = undefined;
    localElement = null;
}
if (remoteStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(remoteStream);
    }
    if(remoteStream.stop) {
        remoteStream.stop();
    }
    remoteStream.onended = null;
    remoteStream = null;
}
if (remoteElement) {
    remoteElement.onerror = null;
    remoteElement.pause();
    remoteElement.src = undefined;
    remoteElement = null;
}
if (peerConnection) {
    peerConnection.close();
    peerConnection = null;
}

我尝试过使用和不使用 removeStream( )调用,我尝试过使用和不使用 stop()调用,我已经尝试了 element.src = element.src = null ,我的想法已经不多了。任何人都知道这是使用API​​时的错误或用户/我的错误吗?

I've tried with and without the removeStream() call, I've tried with and without the stop() call, I've tried the element.src="" and element.src=null, I'm running out of ideas. Anyone know if this is a bug or user/my error in the use of the API?

编辑:我设置了我的默认设备(使用Windows)对于在使用时有照明的相机,并且在停止时,相机指示灯熄灭,因此这可能是Chrome错误。我还发现,如果我使用 chrome:// settings / content 将麦克风设备更改为默认以外的任何设备,则Chrome音频会完全失败。最后,我意识到使用 element.src = undefined 会导致Chrome尝试加载资源并抛出404,因此显然不正确...所以回到 element.src =''就此。

I set my default device (using Windows) to a camera that has a light when it's in use, and upon stopping, the camera light goes off, so perhaps this is a Chrome bug. I also discovered that if I use chrome://settings/content to change the microphone device to anything other than "Default", Chrome audio fails altogether. And finally, I realized that using element.src=undefined resulted in Chrome attempting to load a resource and throwing a 404 so that's clearly not correct... so back to element.src='' on that.

推荐答案

结束我的错(是的,令人震惊)。结果我没有在 onUserMediaSuccess 中正确保存 localStream getUserMedia ...一旦设置完毕,Chrome就会关闭闪烁的录制图标。这并没有解释其他异常,但它结束了问题的主要观点。

Ended up being my fault (yes, shocking). Turns out I wasn't saving localStream correctly in the onUserMediaSuccess callback of getUserMedia... once that was set, Chrome is turning off the blinking recording icon. That didn't explain the other anomalies, but it closes the main point of the question.

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

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