|
Hi all, I’m trying to programmatically play a wav file through
a USB Sound card, but it only works when I set it as the default Audio Playback
device in Control Panel. line = (SourceDataLine) AudioSystem.getLine(info); ß Get’s the default audio
playback device from the OS. When I try to access the device specifically to play audio, it
doesn’t work. Here’s the code: Mixer.Info [] mixers = AudioSystem.getMixerInfo(); Mixer.Info mixerInfo = null; for (int i = 0; i < mixers.length; i++){ mixerInfo = mixers[i]; System.out.println("Name:
"+mixerInfo.getName()); System.out.println("Desc:
"+mixerInfo.getDescription()); System.out.println("Vendor:
"+mixerInfo.getVendor()); System.out.println("Ver:
"+mixerInfo.getVersion()); if ("C-Media USB Headphone
Set".equals(mixerInfo.getName())) break; } Mixer mixer = AudioSystem.getMixer(mixerInfo); … SourceDataLine line = null; DataLine.Info info = new
DataLine.Info(SourceDataLine.class, audioFormat); try { Line [] lines =
mixer.getSourceLines(); System.out.println("# of
SourceLines: "+lines.length); ß output: # of SourceLines: 0 for (int i=0; i < lines.length;
i++){ line = (SourceDataLine) lines[i]; break; } if (line == null) System.exit(1); /* The line is there, but it is not yet
ready to receive audio data. We have to open
the line. */ line.open(audioFormat); } catch (LineUnavailableException e) { e.printStackTrace(); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } My program will be playing audio over multiple USB sounds
cards connected to a single PC, so I need to be able to play sound over a
specific sound card. Any ideas why I can’t get a SourceDataLine from the
USB mixer? Enrico Goosen Software Developer SAICOM TECHNOLOGY TEL: +2721
555 0726 FAX: +2721 555 0821 CEL: +2783 305 5676 EMAIL: [EMAIL PROTECTED] |
