I am having a problem with sound in my program, it takes information from a
TargetDataLine, put's it in a temporary file, then takes it back out of the
temporary file and plays it using a SourceDataLine. currently, it does not
play back.
andrewjj20
the play method:
class Player implements Runnable {
public Player() {
}
public void run() {
try {
int bufferSize = (int)(format.ge tFrameSize()*ra te*1);
byte[] bytes = new byte[(int)bufferSize/12];
lineOut.open(fo rmat,bufferSize );
stopS = false;
recording = false;
playing = true;
if (debug) {
print("playing" );
}
status.setText( "Playing");
lineOut.start() ;
while (!stopS) {
if (in.available() != 0) {
if(lineOut.avai lable() != 0) {
in.read(bytes);
lineOut.write(b ytes, 0, bytes.length);
}
} else {
stopS = true;
resetGUI();
}
}
lineOut.drain() ;
lineOut.stop();
lineOut.close() ;
lineOut = null;
stopS = false;
recording = false;
playing = false;
status.setText( "Done");
if (debug) {
print("Done");
}
} catch (LineUnavailabl eException ex) {
error("I can't acces the nessesary audio functions now");
} catch (IOException ex) {
error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
}
}
}
the record method:
class Recorder implements Runnable {
public Recorder() {
}
public void run() {
try {
int bufferSize = (int)(format.ge tFrameSize()*ra te*0.2);
byte[] bytes = new byte[(int)bufferSize/5];
lineIn.open(for mat,bufferSize) ;
if (debug){
print("recordin g");
}
stopS = false;
lineIn.start();
status.setText( "Recording" );
recording = true;
while (!stopS) {
lineIn.read(byt es, 0, bytes.length);
out.write(bytes .length);
}
lineIn.stop();
out.close();
lineIn.close();
lineIn = null;
out = null;
stopS = false;
recording = false;
modified = true;
newFile = false;
status.setText( "Done");
if (debug) {
print("Done");
}
} catch (LineUnavailabl eException ex) {
error("I can't acces the nessesary audio functions now");
} catch (IOException ex) {
error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
}
}
}
TargetDataLine, put's it in a temporary file, then takes it back out of the
temporary file and plays it using a SourceDataLine. currently, it does not
play back.
andrewjj20
the play method:
class Player implements Runnable {
public Player() {
}
public void run() {
try {
int bufferSize = (int)(format.ge tFrameSize()*ra te*1);
byte[] bytes = new byte[(int)bufferSize/12];
lineOut.open(fo rmat,bufferSize );
stopS = false;
recording = false;
playing = true;
if (debug) {
print("playing" );
}
status.setText( "Playing");
lineOut.start() ;
while (!stopS) {
if (in.available() != 0) {
if(lineOut.avai lable() != 0) {
in.read(bytes);
lineOut.write(b ytes, 0, bytes.length);
}
} else {
stopS = true;
resetGUI();
}
}
lineOut.drain() ;
lineOut.stop();
lineOut.close() ;
lineOut = null;
stopS = false;
recording = false;
playing = false;
status.setText( "Done");
if (debug) {
print("Done");
}
} catch (LineUnavailabl eException ex) {
error("I can't acces the nessesary audio functions now");
} catch (IOException ex) {
error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
}
}
}
the record method:
class Recorder implements Runnable {
public Recorder() {
}
public void run() {
try {
int bufferSize = (int)(format.ge tFrameSize()*ra te*0.2);
byte[] bytes = new byte[(int)bufferSize/5];
lineIn.open(for mat,bufferSize) ;
if (debug){
print("recordin g");
}
stopS = false;
lineIn.start();
status.setText( "Recording" );
recording = true;
while (!stopS) {
lineIn.read(byt es, 0, bytes.length);
out.write(bytes .length);
}
lineIn.stop();
out.close();
lineIn.close();
lineIn = null;
out = null;
stopS = false;
recording = false;
modified = true;
newFile = false;
status.setText( "Done");
if (debug) {
print("Done");
}
} catch (LineUnavailabl eException ex) {
error("I can't acces the nessesary audio functions now");
} catch (IOException ex) {
error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
}
}
}
Comment