Question

I'm trying to learn the Java Sound API so I wrote a short program to find all of the Mixers installed on my laptop and to check if they have headphone Ports. Here's my code

import javax.sound.sampled.*;

public class FindHeadphonePort {
    public static void main(String[] args) throws LineUnavailableException {
        Mixer.Info[] info = AudioSystem.getMixerInfo();
        Line.Info[] mixerTargetLineInfos;
        Port headphonePort;
        for(int i = 0; i < info.length; i++) {
            System.out.println(i + " " + info[i].getName() + "\n");
            mixerTargetLineInfos = AudioSystem.getMixer(info[i]).getTargetLineInfo();

            // SEE IF MIXER HAS A HEADPHONE PORT.
            if(AudioSystem.getMixer(info[i]).isLineSupported(Port.Info.HEADPHONE)) {
                System.out.println(i + " " + info[i].getName() + " has a headphone port");
                headphonePort = (Port)AudioSystem.getMixer(info[i]).getLine(Port.Info.HEADPHONE);
            }
        }
    }
}  

and my output is this:

0 Primary Sound Driver

1 Speakers (Realtek High Definition Audio)

2 Primary Sound Capture Driver

3 Microphone (Realtek High Defini

4 Port Speakers (Realtek High Definiti

5 Port Microphone (Realtek High Defini

which implies I have no Mixers installed which support headphone Ports, in spite of the fact that I'm listening to music through headphones as I write this. Could someone please explain to me what I'm doing wrong?

Thanks!

Was it helpful?

Solution

It implies the headphone is not a separate output -- which it usually isn't, unless you've got pro-level audio equipment where the headphones are separate output channels. Headphones are typically just plugged into speaker output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top