I got this error: Java lang out of memory when i am saving audio in aByteArrayOutputStream,i can only record about 8 minutes. The initial size of memory is: 256m
My code is:
public void run(){
int frameSizeInBytes = frtoData.getFrameSize();
int bufferLengthInFrames = line.getBufferSize() / 8;
bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
bufferTemp = new byte[bufferLengthInBytes];
while (!stopped) {
if (paused) {
synchronized (this) {
while (paused) {
try {
position = (int) (line.getMicrosecondPosition() / 1000000);
this.wait();
} catch (InterruptedException ex) {
Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
if ((numBytesRead = linea.read(bufferTem, 0, bufferLengthInBytes)) == -1) {
break;
}
rewind.write(bufferTemp 0, numBytesRead);
}
code}
rewind is an object of a class: RewindAudio that extends from ByteArrayOutputStream.
I can save more data audio,about 17 minutes, if i increment the size of memory with this: -Xmx450m, but i have to get to at least 1 hour.