Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6732060

Unexpected LineUnavailableException

XMLWordPrintable

      An attempt to open a data line (explicitly or implicitly) leads to LineUnavailableException if made after calling MidiSystem.getSequencer(true) or MidiSystem.getReceiver().
      See the example below.

      -------------------------------------------------------------------------------------
      package testapp.sound;

      import javax.sound.midi.MidiSystem;
      import javax.sound.midi.MidiUnavailableException;
      import javax.sound.midi.Synthesizer;

      public class LUE {
          public static void main(String[] args) {
              LUE inst = new LUE();
              
              try {
                  inst.m1(args);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          
          public void m1(String[] args) throws Exception {

              try {
                  
                  // MidiSystem.getTransmitter(); - throws MUE, OK
                  // MidiSystem.getSynthesizer(); - OK
                  // MidiSystem.getSequencer(false); - OK
                  
                  // calling this makes initiateLUE() throw LUE
                  MidiSystem.getSequencer(true);
                  
                  // calling this makes initiateLUE() throw LUE
                  // MidiSystem.getReceiver();
                  
              } catch (MidiUnavailableException e) {
                  e.printStackTrace();
                  System.out.println("MUE thrown, OK. Moving on.");
              }
              
              initiateLUE();
          }

          private void initiateLUE() throws Exception {
              Synthesizer synth = MidiSystem.getSynthesizer();
              synth.open();
              synth.close();
          }

      }
      -------------------------------------------------------------------------------------

      The output:
      -------------------------------------------------------------------------------------
      > java -cp classes testapp.sound.LUE
      javax.sound.midi.MidiUnavailableException: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
              at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:777)
              at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:712)
              at testapp.sound.LUE.initiateLUE(LUE.java:41)
              at testapp.sound.LUE.m1(LUE.java:36)
              at testapp.sound.LUE.main(LUE.java:12)
      -------------------------------------------------------------------------------------

            darcy Joe Darcy
            ashusher Alexander Shusherov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: