简体   繁体   English

如何检测麦克风是否被任何应用程序使用

[英]How to detect if a microphone is used by any application

I wrote a program that changes my light depending on whether I'm in a meeting or not.我写了一个程序,根据我是否在开会来改变我的灯光。 The easiest way to detect this is to check if the microphone is on.检测到这一点的最简单方法是检查麦克风是否打开。 Currently, I check if a microphone icon appears on the screen (OpenCv):目前,我检查屏幕上是否出现麦克风图标(OpenCv): 在此处输入图像描述

I'm sure it's not the most optimal solution.我敢肯定这不是最佳解决方案。 Is there any way in Java to detect the fact that a microphone is being used? Java中有什么方法可以检测到正在使用麦克风的事实吗?

A few years ago I was investigating how to transmit audio through the network, and I wrote simple ugly project.几年前我在研究如何通过网络传输音频,我写了一个简单的丑陋项目。

And to check if a mic is ready to use I used:为了检查麦克风是否可以使用,我使用了:

javax.sound.sampled.TargetDataLine microphone = AudioSystem.getTargetDataLine(null);
if (!microphone.isOpen()) {
    // ...
}

Maybe it's a bit useless info but I hope it can be useful direction!也许这是一些无用的信息,但我希望它可以成为有用的方向!

Link to class: MicrophoneReader.java课程链接: MicrophoneReader.java

You may check Windows registry, checking tray or other means for microphone usage您可以检查 Windows 注册表、检查托盘或其他方式来了解麦克风的使用情况

Detecting if mic/camera is in use? 检测麦克风/摄像头是否正在使用?

Note:笔记:

Microsoft warns that desktop apps can record sound without ever notifying Windows.微软警告说,桌面应用程序可以在不通知 Windows 的情况下录制声音。 Because they're not subject to the sandbox restrictions of Microsoft Store apps, a desktop program can directly interface with your microphone hardware.因为它们不受 Microsoft Store 应用程序的沙盒限制,桌面程序可以直接与您的麦克风硬件交互。 This means malicious software could record without Windows being aware, so it won't show up in the list or display the microphone icon in the system tray.这意味着恶意软件可以在 Windows 不知情的情况下进行录制,因此它不会出现在列表中,也不会在系统托盘中显示麦克风图标。

Detecting if mic/camera is in use? 检测麦克风/摄像头是否正在使用? How to see which apps are using your microphone in Windows 10 如何在 Windows 10 中查看哪些应用正在使用您的麦克风

Thanks to Eskandar Abedini I was able to do it!感谢 Eskandar Abedini,我能够做到! Below is the entire code:下面是整个代码:

public enum RegistryType {

    MICROPHONE("microphone"),
    WEBCAM("webcam");

    private final String pathValue;

    RegistryType(String pathValue) {
        this.pathValue = pathValue;
    }

    public String getNonPackagePath() {
        return "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CapabilityAccessManager\\ConsentStore\\" + pathValue + "\\NonPackaged";
    }

}

public class RegistryManager {

    private static final String LAST_USED_TIME_STOP = "LastUsedTimeStop";
    private static final Long LAST_USED_TIME_STOP_VALUE = 0L;

    private RegistryManager() {
    }

    public static boolean isMicrophoneWorking() {
        return isDeviceWorking(MICROPHONE);
    }

    public static boolean isWebcamWorking() {
        return isDeviceWorking(WEBCAM);
    }
    private static boolean isDeviceWorking(final RegistryType registryType) {
        final String[] folders = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, registryType.getNonPackagePath());
        return Arrays.stream(folders)
                .map(folder -> registryType.getNonPackagePath() + "\\" + folder)
                .map(register -> Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, register, LAST_USED_TIME_STOP))
                .anyMatch(lastUsedTimeStop -> LAST_USED_TIME_STOP_VALUE.compareTo(lastUsedTimeStop) >= 0);
    }

}

And I also had to use: https://github.com/java-native-access/jna而且我还必须使用: https ://github.com/java-native-access/jna

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM