Cleanup AudioRecord if socket throws an exception

Previously an IOException would prevent the AudioRecord
from being cleaned up.
This commit is contained in:
Branden Archer
2015-12-28 16:08:59 -05:00
parent 0c45351c5a
commit 375242d6fb

View File

@@ -67,21 +67,27 @@ public class MonitorActivity extends Activity
audioEncoding, bufferSize); audioEncoding, bufferSize);
byte[] buffer = new byte[bufferSize*2]; byte[] buffer = new byte[bufferSize*2];
audioRecord.startRecording();
OutputStream out = socket.getOutputStream(); try
socket.setSendBufferSize(bufferSize);
Log.d(TAG, "Socket send buffer size: " + socket.getSendBufferSize());
while (socket.isConnected() && Thread.currentThread().isInterrupted() == false)
{ {
int read = audioRecord.read(buffer, 0, bufferSize); audioRecord.startRecording();
out.write(buffer, 0, read);
}
socket.close(); OutputStream out = socket.getOutputStream();
audioRecord.stop();
socket.setSendBufferSize(bufferSize);
Log.d(TAG, "Socket send buffer size: " + socket.getSendBufferSize());
while (socket.isConnected() && Thread.currentThread().isInterrupted() == false)
{
int read = audioRecord.read(buffer, 0, bufferSize);
out.write(buffer, 0, read);
}
}
finally
{
audioRecord.stop();
socket.close();
}
} }
@Override @Override