2013-02-28 272 views
-1

我在Chrome 25上成功使用getUserMedia和RTCPeerConnection将音频从网页连接到另一方,但我无法使API停止红色闪烁指示在该页面上使用媒体的Chrome选项卡中的图标。我的问题实质上是Stop/Close webcam which is opened by navigator.getUserMedia的重复,除了解决方案没有工作。如果我有一个只使用getUserMedia且没有远程媒体(无对等)的页面,则停止相机会关闭闪烁的选项卡指示灯。添加远程流似乎是一个问题。这就是我目前得到了我的“亲密”代码:使用getUserMedia和RTCPeerConnection停止/关闭摄像头Chrome 25

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​​的错误?

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

回答

2

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

+0

几个月前我有类似的问题:http://stackoverflow.com/a/14366623/1916258 – asgoth 2013-03-19 20:23:22

0

只是通过WebRTC规范拖网后昨天得到了这个工作。我不知道这是否是“正确”的方式,但是我发现,在删除流之后用新的报价重新谈判PeerConnection确实有窍门。

var pc = peerConnections[socketId]; 
pc.removeStream(stream); 
pc.createOffer(function(session_description) { 
    pc.setLocalDescription(session_description); 
    _socket.send(JSON.stringify({ 
    "eventName": "send_offer", 
    "data":{ 
     "socketId": socketId, 
     "sdp": session_description 
     } 
    })); 
}, 
function(error) {}, 
defaultConstraints); 
+0

感谢您的帖子;我在我的close代码上面添加了一个位于'peerConnection.close'行上方的'peerConnection.createOffer',但奇怪的是,它似乎以某种方式失败了,没有调用成功回调函数或失败回调函数,也没有抛出错误。不幸的是我的小铬标签录制图标仍然在闪烁。我会继续工作这个角度,如果我找到任何东西,请回复,谢谢。 – mark 2013-03-01 13:28:00

相关问题