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.
How to find installed Mixer which supports headphone Port in Java
質問
I'm trying to learn the Java Sound API so I wrote a short program to find all of the Mixer
s installed on my laptop and to check if they have headphone Port
s. 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 Mixer
s installed which support headphone Port
s, 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!
解決
所属していません StackOverflow