Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.IllegalArgumentException (problem when playing audio)

843802Jun 13 2008 — edited Jun 13 2008
i play an audio with code like this:
private AudioFormat getAudioFormat(){

    float sampleRate = 16000;
    //8000,11025,16000,22050,44100
    int sampleSizeInBits = 16;
    //8,16
    int Channels =2;
    //1,2
    boolean Signed =true;
    //true,false
    boolean bigEndian = false;
    //true,false
    return new AudioFormat(sampleRate,
                           sampleSizeInBits,
                           Channels,
                           Signed,
                           bigEndian);
   
  }//end getAudioFormat

private void playAudio() {
    try{
                      
      audioFormat = getAudioFormat();
      //System.out.println(audioFormat);
      //tformat.setText(audioFormat.toString());
      DataLine.Info dataLineInfo =
                          new DataLine.Info(
                            SourceDataLine.class,
                                    audioFormat);

      sourceDataLine =
             (SourceDataLine)AudioSystem.getLine(
                                   dataLineInfo);
     
    }catch (Exception e) {
       JOptionPane.showMessageDialog(null, e.getMessage(),"Message",JOptionPane.ERROR_MESSAGE);
   
    }//end catch
  }//end playAudio 
   
  //begin playing
playAudio();
int cnt=1;  
byte dt[]=new byte[1000];      
    try{
            sourceDataLine.open(audioFormat,sourceDataLine.getBufferSize());
              sourceDataLine.start();
     }catch(LineUnavailableException e){
             e.printStackTrace();
         }
      do { // process messages sent from client     
         try {      
            cnt=sourceDataLine.read(dt,0,dt.length);
            if(cnt > 0){
          sourceDataLine.write(
                             temp1, 0, cnt);
                               
        }
           
         }
         catch(IllegalArgumentException ex){
            ex.printStackTrace(); 
        
         }
        

      } while ( cnt!=-1 );
when i playing a few minutes i got bug like this
java.lang.IllegalArgumentException: illegal request to write non-integral number of frames (450 bytes, frameSize = 4 bytes). please tell me what wrong?

Edited by: Christian_info on Jun 13, 2008 1:25 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2008
Added on Jun 13 2008
0 comments
337 views