使用网络音频API检查选定的麦克风是否已静音 [英] Check if selected microphone is muted or not with web audio api
问题描述
通过使用以下内容,我们可以提示用户选择受音频和视频源限制的首选媒体输入设备(当前仅对Chrome支持感兴趣).
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);
});
任何人都知道是否有公开的API可以检测用户选择的输入设备当前是否处于静音状态吗?输入设备可以是板载麦克风,外部麦克风,也可以是在系统中显示为硬件设备的软件定义的麦克风.
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.
推荐答案
您可以通过迭代MediaStream
返回的数组来检查每个MediaStreamTrack
的属性.muted
Boolean
值
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));
您还可以利用mute
和unmute
MediaStreamTrack
事件.
You can also utilize mute
and unmute
MediaStreamTrack
events.
这篇关于使用网络音频API检查选定的麦克风是否已静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!