Perhaps you can change and use this. The following code is used to select audio output devices on my two applets. I was only interested in the output lines, not the ports or input lines. The first part lists the options in the parameter group in the "Myrar" drop-down menu. The second part sets the mixer variable based on the selected option.
private void createMenuBars(){ JMenuBar menuBar = new JMenuBar(); menuBar.setBounds(0, 0, 60, 20); JMenu optionMenu = new JMenu("Options"); JMenuItem pickMixers = new JMenuItem("Select a Playback Path"); optionMenu.add(pickMixers); optionMenu.addSeparator(); ButtonGroup mixerSelections = new ButtonGroup(); addMixerOption("default sound system", mixerSelections, optionMenu, true); AudioFormat audioFmt = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, false); Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for (Mixer.Info info : mixers) { Mixer mixer = AudioSystem.getMixer(info); try { // System.out.println(info); Info sdlLineInfo = new DataLine.Info(SourceDataLine.class, audioFmt); // test if line is assignable @SuppressWarnings("unused") SourceDataLine sdl = (SourceDataLine) mixer.getLine(sdlLineInfo); // if successful, add to list addMixerOption(info.getName() + " <> " + info.getDescription(), mixerSelections, optionMenu, false); } catch (LineUnavailableException e) { //e.printStackTrace(); System.out.println("Mixer rejected, Line Unavailable: " + info); } catch (IllegalArgumentException e) { //e.printStackTrace(); System.out.println("Mixer rejected, Illegal Argument: " + info); } } menuBar.add(optionMenu); add(menuBar,0); } private void addMixerOption(String optionName, ButtonGroup bg, JMenu menu, boolean isSelected { JRadioButtonMenuItem newOption = new JRadioButtonMenuItem(optionName); bg.add(newOption); newOption.setSelected(isSelected); menu.add(newOption); newOption.addActionListener(new OptionListener()); newOption.setActionCommand(optionName); }
The mixer variable was selected here when selecting an option.
public class OptionListener implements ActionListener { @Override public void actionPerformed(ActionEvent arg0) { String optionName = arg0.getActionCommand(); Boolean defaultMixer = true; Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for (Mixer.Info info : mixers) { if (optionName.equals(info.getName()+" <> "+info.getDescription())) { System.out.println("Option selected > " + info.getName()); System.out.println(" description > " + info.getDescription()); System.out.println(" class > " + info.getClass()); appMixer = AudioSystem.getMixer(info); System.out.println(appMixer); defaultMixer = false; } } if (defaultMixer) { System.out.println("Using default mixer, whatever that is..."); appMixer = null; } } }
There is an abundance of console messages. I use this at http://hexara.com/VSL/JTheremin.htm
source share