This discussion is archived
1 Reply Latest reply: Nov 10, 2011 6:27 PM by 810200 RSS

Detect when a USB mic is plugged in or unplugged

837633 Newbie
Currently Being Moderated
It seems like JavaSound doesn't detect when a USB Microphone is plugged in or removed.

If plugged in while my java application is running, its not detected. Worse, if unplugged it still thinks its a valid mixer.

I have to relaunch the VM. Is there any way around this? I'm running Java 1.6.0_24 on Windows 7.

Here is the code I'm using to get the list of microphones:
    public LinkedList<Mixer.Info> getTargetMixers()
    {
        Line.Info targetDLInfo = new Line.Info(TargetDataLine.class);
        
        LinkedList<Mixer.Info> targetMixers = new LinkedList<Mixer.Info>();

        // Get all the mixers
        Mixer.Info[] mixerInfoArray = AudioSystem.getMixerInfo();
        for(int i=0; i<mixerInfoArray.length; i++)
        {
            Mixer.Info mixerInfo = mixerInfoArray;
try
{
Mixer mixer = AudioSystem.getMixer(mixerInfo);
if(mixer.isLineSupported(targetDLInfo))
targetMixers.add(mixerInfoArray[i]);
}
catch(Exception ex)
{
logger_.error("Error getting mixer: " + mixerInfo.getName(), ex);
}
}

return targetMixers;
}
Thanks Much...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points