我有一个UWP应用程序,我试图检测麦克风是否被任何应用程序使用。
下面是从我的系统中获取麦克风的代码。
namespace CallDetector
{
public sealed partial class MainPage : Page
{
private DispatcherTimer timer;
private MediaCapture mediaCapture;
public MainPage()
{
this.InitializeComponent();
StartMicrophoneStatusCheckTimer();
}
private void StartMicrophoneStatusCheckTimer()
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(5);
timer.Tick += Timer_Tick;
timer.Start();
}
private async void Timer_Tick(object sender, object e)
{
await CheckMicrophoneStatus();
}
private async Task CheckMicrophoneStatus()
{
var microphoneDevice = await GetMicrophoneDeviceAsync();
if (microphoneDevice != null && microphoneDevice.IsEnabled)
{
var msg = new MessageDialog($"Microphone device found: {microphoneDevice.Name}");
await msg.ShowAsync();
}
else
{
var msge = new MessageDialog("No microphone device found.");
await msge.ShowAsync();
}
}
private static async Task<DeviceInformation> GetMicrophoneDeviceAsync()
{
var microphoneSelector = MediaDevice.GetAudioCaptureSelector();
var microphoneDevices = await DeviceInformation.FindAllAsync(microphoneSelector);
return microphoneDevices.FirstOrDefault();
}
}
}
如何检测麦克风被哪个应用程序使用(通过使用UWP C#)?
1条答案
按热度按时间xoshrz7s1#
我检查了Namespace Windows.Media.Devices中的API,目前没有API可以获取哪个应用正在使用麦克风。以防万一,我也检查了Win32 Audio Session Events,也无法得到哪个进程正在使用麦克风,它只能注册和接收一些特定会话事件的通知。