Cleanup AudioRecord if socket throws an exception
Previously an IOException would prevent the AudioRecord from being cleaned up.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user