This discussion is archived
1 2 Previous Next 15 Replies Latest reply: May 26, 2011 1:10 PM by captfoss RSS

Problem with Line Unsupported

847432 Newbie
Currently Being Moderated
Hello,

So i have a problem on my application related with capturing audio.

So my application have a JComboBox which have the available mixers and the user choose one specific for the microphone. After that i send that a method capture()
public void captureAudio(){
              
                 
        try{
            format = getFormat();
            
            //Mixer.Info[] mixerInfo =AudioSystem.getMixerInfo();

            //DataLine.info get the information about the line.
            DataLine.Info info = new DataLine.Info(TargetDataLine.class,format);
            
        
            mixerPort1 = AudioSystem.getMixer((Mixer.Info)pref.CBMic1.getSelectedItem()); //Here as you can see i get the selected mixer from the JComboBox
            
            System.out.println("MixerP1"+mixerPort1);
            // get the info from the desired line.
            micLine1 = (TargetDataLine)AudioSystem.getLine(info);
            
            //Get a TargetDataLine on the selected mixer.
            micLine1 = (TargetDataLine) mixerPort1.getLine(info);
            micLine1.open(format);
            micLine1.start();
            
            Microphone1Thread mic1Thread = new Microphone1Thread();
            mic1Thread.start();

    } catch (Exception e) {
      
      e.printStackTrace();
      System.exit(0);

    }
    }
But when i want to start the capture give me this error:

java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 8 bit, mono, 1 bytes/frame,
     at com.sun.media.sound.DirectAudioDevice.getLine(DirectAudioDevice.java:157)
     at App.Microphone1.captureAudio(Microphone1.java:202)
     at App.Microphone1$CaptureAudioWorker.doInBackground(Microphone1.java:80)
     at App.Microphone1$CaptureAudioWorker.doInBackground(Microphone1.java:59)
     at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
     at javax.swing.SwingWorker.run(SwingWorker.java:316)
     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
     at java.lang.Thread.run(Thread.java:662)

Any tip? I dont know what i need to do.
  • 1. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    DavidHenriques wrote:
    java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 8 bit, mono, 1 bytes/frame,
    Sounds like the mixer doesn't support TDLs, or it doesn't support TDLs for that format.

    I'd query your system to make sure what you're expecting to work should work...
    http://www.developerfusion.com/article/84314/wired-for-sound/

    Make sure the selected mixer supports TDLs, and make sure that the TDLs support the requested format.
  • 2. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Hum, but that is weird because without making this was working. Was working when i choose the mixer by the code.

    The error is in this line:

    micLine1 = (TargetDataLine) mixerPort1.getLine(info);

    I will check that

    Edited by: DavidHenriques on May 16, 2011 2:14 PM
  • 3. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    But is weird because i have the getFormat method:
    public AudioFormat getFormat(){
            
              float sampleRate = 44100.0F;
              //8000,11025,16000,22050,44100
    
                    int sampleSizeInBits = 8;
              //8,16
    
                    int channels = 1;
              //1,2
              boolean signed = true;
    
              boolean bigEndian = true;
    
                    return new AudioFormat(sampleRate,sampleSizeInBits,channels,signed,bigEndian);
          
           }
    And i choose the mixers for capturing audio.
    The capture audio works without choosing the mixer with JComboBox the system works.
  • 4. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    DavidHenriques wrote:
    The capture audio works without choosing the mixer with JComboBox the system works.
    Then it sounds like the error is perhaps in the code you didn't post...

    I'd guess the Mixer.info objects are somehow being corrupted / messed up? Dunno without seeing the code...
  • 5. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Thanks for the tip.

    Well the code of this part is this:

    JComboBox code:
    private void CBMic1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
            
            
            CBMic1 = (JComboBox) evt.getSource();
            CBMic1.getSelectedItem();
                   
        } 
    captureAudio():
    ...
    Preferences pref = new Preferences(); //JComboBox class object
    public TargetDataLine micLine1;
    
    public void captureAudio(){
                         
            try{
                format = getFormat();
                
                //Mixer.Info[] mixerInfo =AudioSystem.getMixerInfo();
    
                //DataLine.info get the information about the line.
                DataLine.Info info = new DataLine.Info(TargetDataLine.class,format);
                
            
                mixerPort1 = AudioSystem.getMixer((Mixer.Info)pref.CBMic1.getSelectedItem());
                
                System.out.println("Mixer 1 "+mixerPort1);
                // get the info from the desired line.
                //micLine1 = (TargetDataLine)AudioSystem.getLine(info);
                
                //Get a TargetDataLine on the selected mixer.
                micLine1 = (TargetDataLine) mixerPort1.getLine(info);
                micLine1.open(format);
                micLine1.start();
                
                Microphone1Thread mic1Thread = new Microphone1Thread();
                mic1Thread.start();
    
        } catch (Exception e) {
          
          e.printStackTrace();
          System.exit(0);
    
        }
        }
    The output says is thé line that i mentioned before which is giving error, but i think is this:

    mixerPort1 = AudioSystem.getMixer((Mixer.Info)pref.CBMic1.getSelectedItem());

    I don't know if this is right, or running right.
  • 6. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    DavidHenriques wrote:
    mixerPort1 = AudioSystem.getMixer((Mixer.Info)pref.CBMic1.getSelectedItem());
    I don't know if it's the cause of the problem, but you're definately breaking some coding "best practices" by storing data in Swing components.

    You should obtain the list of mixer.info objects and store it separately from the JComboBox, build a String array by iterating through the mixer info objects...build the JComboBox from the String[], and then use box.getSelectedIndex to get the index of the selected option and use it to fetch the Mixer.info object from the array you stored previously.

    So, the array of Mixers should be kept separate from the JComboBox entirely...
  • 7. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Thanks for the tips captfoss.

    In here i put this: CBMic1.setModel(new javax.swing.DefaultComboBoxModel(mixerInfo);

    1 - I need to create an Mixer.Info array to put the list of mixers ?

    2 - I need to create an String array to put what in there? the name of the mixer? For example stringArray[] = mixerInfo.getName() ?

    3 - Create the JComboBox and introduce "new JComboBox(stringArray) ?

    4 - In the actionPerfomed from the JComboBox put ComboBox.getSelectedIndex?

    5 - Need to put the mixer selected in the mixerPort1 = getMixer(?) ?



    Edited by: DavidHenriques on May 18, 2011 1:46 PM

    Edited by: DavidHenriques on May 18, 2011 3:25 PM
  • 8. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    1 - I need to create an Mixer.Info array to put the list of mixers ?
    Really, you just need to store the result of a call to AudioSystem.getMixerInfo(), which returns a Mixer.info[]...

    How are you currently getting the list of mixers? Some other way?
    2 - I need to create an String array to put what in there? the name of the mixer? For example stringArray[] = mixerInfo.getName() ?
    Because you don't want to give Swing the Mixer.info list (because it might mess it up somehow) you need to create a String array containing the strings you want associated with the mixers... so you can do this however you want. getName, toString, whatev...
    3 - Create the JComboBox and introduce "new JComboBox(stringArray) ?
    Yeah, I believe that's the proper method...
    4 - In the actionPerfomed from the JComboBox put ComboBox.getSelectedIndex?
    5 - Need to put the mixer selected in the mixerPort1 = getMixer(?) ?
    When the selection of the combo box changes, you'll get the event. You can then get the selected index (call it X), and then you can get the Xth element of the Mixer.info array you stored above... so

    mixerPort1 = mixerArray[x];
  • 9. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Hello,

    I made a method called listMixers():
    public void listMixers(){
     
          System.out.println("Available mixers:");
          
          for(int arrayIndex = 0; arrayIndex < mixerInfo.length;  arrayIndex++){
          
                mixerData[arrayIndex] = mixerInfo[arrayIndex].getName();
                
                System.out.println("Mixer: "+mixerInfo[arrayIndex]);
             
          }
        }
    the variable mixerData is the String[] and the mixerInfo is the Mixer.Info[] and i put the length of the String[] equals of the Mixer.Info[] and i put the string to the mixerData calling .getName().

    About JComboBox i put this:
    CBMic1 = new javax.swing.JComboBox(mixerData);
    
    CBMic1.setModel(new javax.swing.DefaultComboBoxModel(mixerInfo));
    In the setModel() i put the array mixerInfo which is equals to mixerInfo[] = AudioSystem.getMixerInfo(); . So i need to avoid this but since i am using the netbeans the generated code generated this line with setModel and the setModel only accept Vector, Object.

    in the event from the JComboBox i have this:
    private void CBMic1ActionPerformed(java.awt.event.ActionEvent evt) {    
    CBMic1 = (JComboBox) evt.getSource();
    CBMic1.getSelectedIndex();
    }
    For that i read from your answer i need to create a variable int X create a cycle for?
  • 10. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    DavidHenriques wrote:
    For that i read from your answer i need to create a variable int X create a cycle for?
    I have no idea what you just said...

    All you need to do is find out which index is selected, and grab the associated mixer.info object from your array... I feel like you're making this harder than it needs to be.
  • 11. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Yes,

    I think i am making this harder than need to be, but since i am newbie on this i having a little problems to understand some problems.

    I can't make this easy thing, getting the object of the array associated to the index position from the JComboBox :/

    My self-estime is low xD
  • 12. Re: Problem with Line Unsupported
    captfoss Pro
    Currently Being Moderated
    comboBox.getSelectedItem is going to return the index of the item the user selected in the list, which is going to be based on the String array you gave it. You use that index to get the selected element from your Mixer.info array which you used to construct the string array which you used to construct the JComboBox in the first place.

    Mixer.Info[] => String[] => JComboBox... so when the user selects the nth element of the JComboBox, it's the nth element of the String[], which is the nth element of the Mixer.Info[]

    I don't know how much simplier I can state that. If you don't understand that, you need to take an "Intro to Programming" class...
  • 13. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    Hello,

    Sorry noobish... Well i have already the JcomboBox showing the list of mixers available using the String[]. but now i don't know how i will associate the .getSelectedItem to the String[index] and String[index] to the Mixer.Info[].

    Need to make a cycle? Tips?
  • 14. Re: Problem with Line Unsupported
    847432 Newbie
    Currently Being Moderated
    I solved the problem. Thanks for the help captfoss.

    Was a simple thing to do.

    I made a method where returns a variable with the index position from JComboBox and than pass that variable to the mixer.info[].
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points