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