pvsnambiar
pvsnambiar

Reputation: 113

how get available audio devices connected using java in mac osx

i was trying to get the available mixtures in MAC OSX using the below code. Even though i connected 3 different audio device, and able to see the same in system sound settings,below code doesn’t display all. i.e. mix.getMixerInfo()).isLineSupported(info) is not allowing to display anything and even not able to connect using java . The same is working fine with windows version.

  public static void main(String[] args) {
    String sf_ringtone = "/Users/abc.WAV";
    AudioInputStream stream = null;

    try {
        stream = AudioSystem.getAudioInputStream(new File(sf_ringtone));
    } catch (UnsupportedAudioFileException ex) {
        System.out.println(ex.getStackTrace().toString());
    } catch (IOException ex) {
        System.out.println(ex.getStackTrace().toString());
    }

    AudioFormat format=null;
    format = stream.getFormat();

    if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
        format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                format.getSampleRate(), format.getSampleSizeInBits() * 2,
                format.getChannels(), format.getFrameSize() * 2,
                format.getFrameRate(), true); // big endian
        stream = AudioSystem.getAudioInputStream(format, stream);
    }

    DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(),
            ((int) stream.getFrameLength() * format.getFrameSize()));

    ArrayList<Mixer> mixerList = (ArrayList<Mixer>) getAllMixer();
    for(Mixer mix:mixerList) {
        System.out.println(" Mixture  "+mix.getMixerInfo().getName());
    }

    ArrayList<String> cmbRingtonePlayback = new ArrayList<String>();
    for (Mixer mix : mixerList) {
        if (AudioSystem.getMixer(mix.getMixerInfo()).isLineSupported(info)) {
            System.out.println(supported mixture :: "+mix.getMixerInfo().getName());                    
        }
    }


}

output:

Mixture Java Sound Audio Engine

Mixture Built-in Input

Mixture JABRA TALK

Mixture Logitech USB Headset

supported mixture :: Java Sound Audio Engine

Is this a limitation of sound API in mac osx ?, or is there any other way to do this in mac?

Upvotes: 1

Views: 737

Answers (1)

pvsnambiar
pvsnambiar

Reputation: 113

This issue faced was with apple Java for OS X 2014-001. Uninstalled java 1.6 from apple and tried with oracle java 1.7. Now this is working fine in both mac osx and windows.

Upvotes: 1

Related Questions