停止WebRTC媒体流
我已经开始使用停止WebRTC媒体流,webrtc,Webrtc,我已经开始使用navigator.mediaDevices.getUserMedia({audio:true,video:false})a媒体流,它工作正常。现在我希望它停止在一个按钮点击,但我找不到任何可行的解决方案。 根据我的研究,WebRTC已经贬低了stream.stop(),但我也发现了一些类似的替代方案,但这里的解决方案也不起作用 是否有可行的解决方案?实例化流: navigator.mediaDevices.getUserMedia({ audio: true, video
navigator.mediaDevices.getUserMedia({audio:true,video:false})
a媒体流,它工作正常。现在我希望它停止在一个按钮点击,但我找不到任何可行的解决方案。
根据我的研究,WebRTC已经贬低了stream.stop(),但我也发现了一些类似的替代方案,但这里的解决方案也不起作用
是否有可行的解决方案?实例化流:
navigator.mediaDevices.getUserMedia({ audio: true, video: false})
.then(stream => {
// attach this stream to window object so you can reuse it later
window.localStream = stream;
// Your code to use the stream
})
.catch((err) =>{
console.log(err);
});
localStream.getTracks().forEach((track) => {
track.stop();
});
删除流:
navigator.mediaDevices.getUserMedia({ audio: true, video: false})
.then(stream => {
// attach this stream to window object so you can reuse it later
window.localStream = stream;
// Your code to use the stream
})
.catch((err) =>{
console.log(err);
});
localStream.getTracks().forEach((track) => {
track.stop();
});
这回答了你的问题吗?