audioInputStream problem with socket
Hi,
I know here is many topics which are close to my own but I can't find answer of them. I'm doing client-server program which can play sounds with streams. I want also play mic data which is coming from other computer. File sending from other computer works well. I have to receive many files and it works also well. I can also play all files I want but this line audioInputStream = AudioSystem.getAudioInputStream(sInputStream);
is my problem. Some files works with it OK but some files don't. With some files after successful playing in that line is occurred following error (its coming with some files 4 times one after the other and then program stops to that line to waiting new data, and when I'm receiving microphone data this error message is coming non-stop and audio is of course not heard):
java.io.IOException: mark/reset not supported
at java.io.InputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.WaveFileReader.getFMT(Unknown Source)
at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source
)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at SipChat_JF$readDataSocketThread.run(SipChat_JF.java:468)
How can I avoid this error? What would be the correction? I can't understand why error is happening 4 times and then program works again OK. And with some files there is no problem. Here is data receiver code:
class readDataSocketThreadextends Thread{
publicvoid run(){
ShowMessage("Data reader thread running...");
try{
sInputStream = dataSock.getInputStream();
//sInputStream = new DataInputStream(dataSock.getInputStream());
}catch (IOException ieo){
ShowMessage("Stream is not gotten from socket...");
}
while (! dataSock.isClosed()){
try{
ShowMessage("Waiting for stream...");
audioInputStream = AudioSystem.getAudioInputStream(sInputStream);
}catch (IOException ex){
ex.printStackTrace();
}catch (UnsupportedAudioFileException ex){
ShowMessage("Filetype is not supported!");
ex.printStackTrace();
}
audioFormat = audioInputStream.getFormat();
System.out.println(audioFormat);
DataLine.Info info =new DataLine.Info(SourceDataLine.class, audioFormat);
try{
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(audioFormat);
line.start();
}catch (LineUnavailableException e){
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
int nBytesRead = 0;
int EXTERNAL_BUFFER_SIZE = 128000;
byte[] abData =newbyte[EXTERNAL_BUFFER_SIZE];
nBytesRead = 0;
while (nBytesRead != -1){
try{
nBytesRead = audioInputStream.read(abData, 0, abData.length);
}catch (IOException e){
e.printStackTrace();
}
if (nBytesRead > 0){
line.write(abData, 0, nBytesRead);
ShowMessage("Writing data to player...");
}
}
line.drain();
line.close();
}
ShowMessage("Data reader is dead...");
}
}
Message was edited by:
jperala
Message was edited by:
jperala

