Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
停止WebRTC媒体流_Webrtc - Fatal编程技术网

停止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();
});

这回答了你的问题吗?