javasoundcard

Monitor the status of sound card on windows using java


I'm developing a java application and I have a sound card that's connected to my computer. I want to monitor the status of sound card by using java. That is, I'll implement a listener that waits for the connection of sound card. Once the sound card is plugged in, my java program would get notified. Is this possible to achieve? I'm searched a lot on Internet, but I found nothing.


Solution

  • This is going to be more complicated if you're using Java. Java runs in a Virtual Machine (JVM) that is specifically intended to shield you, as the programmer, from having to know intimate details of your host system, and also to protect the host system from Java applications getting access to native details like what you're looking for.

    There may be libraries out there that can accomplish what you're looking for, although I did a brief search and didn't come across anything.

    In your situation, I would probably start investigating JNI (Java Native Interface), along with specific Windows APIs you would be hoping to interact with.

    Alternatively -- and I personally like this approach better -- you may be able to write some kind of a very small monitoring program in a different language with better native hardware monitoring support, which could then call, e.g., a REST endpoint in your Java app to send it interesting events.

    Sorry for the bad news. Perhaps someone else will have better news, or a less hand-waving, general response.