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,6 +67,9 @@ public class MonitorActivity extends Activity
audioEncoding, bufferSize); audioEncoding, bufferSize);
byte[] buffer = new byte[bufferSize*2]; byte[] buffer = new byte[bufferSize*2];
try
{
audioRecord.startRecording(); audioRecord.startRecording();
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
@@ -79,9 +82,12 @@ public class MonitorActivity extends Activity
int read = audioRecord.read(buffer, 0, bufferSize); int read = audioRecord.read(buffer, 0, bufferSize);
out.write(buffer, 0, read); out.write(buffer, 0, read);
} }
}
socket.close(); finally
{
audioRecord.stop(); audioRecord.stop();
socket.close();
}
} }
@Override @Override