WebRTC通话后如何释放相机和麦克风? [英] how do I release the camera and microphone after a WebRTC call?
问题描述
结束WebRTC通话后,我似乎无所事事,没有删除浏览器选项卡上的红色图标,表示正在使用相机或麦克风.
After I end a WebRTC call, nothing I seem to do removes the red icon on the browser tab that says the camera or microphone are in use.
我迭代 videoElement.srcObject.getTracks()
中的轨道,并在每个轨道上调用 track.stop()
.然后,我从DOM中删除videoElement,但仍然有红色图标.
I iterate the tracks from videoElement.srcObject.getTracks()
and call track.stop()
on each one. I then delete the videoElement from the DOM, but still I have the red icon.
推荐答案
就我而言,问题是由于我对WebRTC和getUserMedia()的误解导致代码中的错误所致.我实际上是两次调用getUserMedia(),一次是用于本地< video>
元素,另一次是用于添加到RTCPeerConnection.
In my case, the problem was caused by a bug in my code due to my misunderstanding WebRTC and getUserMedia(). I was actually calling getUserMedia() twice, once for the local <video>
element and a second time for adding to the RTCPeerConnection.
解决方法当然是只调用一次getuserMedia()并在两个地方都使用返回的流.
The fix was of course to only call getuserMedia() once and use the returned stream in both places.
这篇关于WebRTC通话后如何释放相机和麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!