How to detect if microphone permissions have been granted in chrome

后端 未结 3 846
谎友^
谎友^ 2021-02-01 22:58

I would liked to detect whether or not microphone permissions have been granted on my site when it loads without actually running something like the following:

n         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 23:09

    you already got the polling method for checking permissions. here is some information from MDN: https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia

    and some more: https://developer.mozilla.org/en-US/docs/WebRTC

    here is an example:

    navigator.getMedia (
    // constraints
       {
          video: true,
          audio: true
       },
    
       // successCallback
       function(localMediaStream) {
          var video = document.querySelector('video');
          video.src = window.URL.createObjectURL(localMediaStream);
          video.onloadedmetadata = function(e) {
             // Do something with the video here.
          };
       },
    
       // errorCallback
       function(err) {
        console.log("The following error occured: " + err);
       }
    
    );
    

提交回复
热议问题