Check if the selected microphone is muted or not using the web audio api

Using the following, we can suggest the user to select the preferred multimedia input device with restrictions on the audio and video source (currently only interested in Chrome support).

navigator.mediaDevices.getUserMedia({audio: true}) .then((stream) => { console.log(stream); }); 

Does anyone know if there is an open API to detect if the user-selected input device is currently disabled or not? The input device will either be a built-in microphone, or an external microphone, or a software microphone, which is displayed in the system as a hardware device.

+5
source share
1 answer

You can check the value of the .muted Boolean property of each MediaStreamTrack , iterate MediaStreamTrack array returned by MediaStream .getAudioTracks() , or by selecting MediaStreamTrack by index from the array.

  navigator.mediaDevices.getUserMedia({audio: true}) .then(stream => { console.log("MediaStreamTrack muted:", stream.getAudioTracks()[0].muted); }) .catch(err => console.log(err)); 

You can also use the mute and unmute MediaStreamTrack .

+3
source

Source: https://habr.com/ru/post/1261811/


All Articles