Selecting Audio Inputs

It’s not realistic to think the user has only one audio input device. The computer might be connected to a headset for audio conferencing, a webcam for video conferencing, and a camcorder for dumping pictures of the summer vacation into iMovie. Ideally, it should be possible to discover connected devices at runtime and specify which is to be used for capture.

How do I do that?

To provide a list of devices, you need to query the SGAudioChannel for what devices are available, and then present the choice to the user. So, take the code from the previous lab and add an AWT Choice called deviceChoice in the constructor (replacing a line with a comment that said “reserved for next lab”). Next, after the SGSoundChannel is created in setUpAudioGrab( ), insert this block of code to search for audio devices, adding the name of each to the deviceChoice:

// create list of input devices
SGDeviceList devices = soundChannel.getDeviceList(0);
int deviceCount = devices.getCount( );
for (int i=0; i<deviceCount; i++) {
  SGDeviceName deviceName = devices.getDeviceName(i);
  // is it available?
  if ((deviceName.getFlags( ) &
       StdQTConstants.sgDeviceNameFlagDeviceUnavailable) =  = 0)
  deviceChoice.add(deviceName.getName( ));
}

You need to update the itemStateChanged() callback to handle AWT events on the deviceChoice—in other words, when the user changes the selection. Fortunately, QuickTime allows you to change the input device by passing in a name, so switching devices is pretty easy. Add ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.