By using the following, we can prompt the user to select their preferred media input device with audio and video source constraints (currently only interested in Chrome support).
navigator.mediaDevices.getUserMedia({audio: true})
.then((stream) => {
console.log(stream);
});
Anyone know if there is an exposed API to detect if the user-selected input device is currently muted or not? The input device would be either an onboard microphone, external mic, or software defined microphone that shows in the system as a hardware device.
You can check property .muted Boolean value of each MediaStreamTrack by iterating the array returned by MediaStream .getAudioTracks() method, or by selecting the 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 utilize mute and unmute MediaStreamTrack events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With