MediaStreams停止后,如何在Chrome浏览器中删除相机权限图标

时间:2016-12-14 13:23:01

标签: javascript google-chrome permissions camera

停止使用相机后,我仍然会在Chrome浏览器中看到相机的权限图标。转动相机后我无法重新加载页面,我应该留在这个页面上。

    var _video = document.getElementById('video');
    var _mediaStream = null;
    navigator.mediaDevices
        .getUserMedia({audio: false, video: true}).then(function (stream) {
            _mediaStream = stream;
            _video.src = window.URL.createObjectURL(stream);
            _video.play();
        });
    document.getElementById('stopCamera').addEventListener('click', function () {
        _video.pause();
        _video.src = '';
        _mediaStream.getVideoTracks().forEach(function (track) {
            track.stop();
        });
        _mediaStream.getAudioTracks().forEach(function (track) {
            track.stop();
        });
        _mediaStream = null;
        _video.parentNode.removeChild(_video);
    });
<button id="stopCamera">Stop Camera</button>
<video id="video" width="640" height="480" autoplay></video>

0 个答案:

没有答案