in src/android/Capture.java [387:439]
public void onAudioActivityResult(Request req, Intent intent) {
Uri uri = intent.getData();
InputStream input = null;
OutputStream output = null;
try {
if (uri == null) {
throw new IOException("Unable to open input audio");
}
input = this.cordova.getActivity().getContentResolver().openInputStream(uri);
if (input == null) {
throw new IOException("Unable to open input audio");
}
output = new FileOutputStream(this.audioAbsolutePath);
byte[] buffer = new byte[getPageSize()];
int bytesRead;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} catch (FileNotFoundException e) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to read input audio: File not found"));
} catch (IOException e) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to read input audio"));
} finally {
try {
if (output != null) output.close();
if (input != null) input.close();
} catch (IOException ex) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to copy input audio"));
}
}
// create a file object from the audio absolute path
JSONObject mediaFile = createMediaFileWithAbsolutePath(this.audioAbsolutePath);
if (mediaFile == null) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: no mediaFile created from " + this.audioAbsolutePath));
return;
}
req.results.put(mediaFile);
if (req.results.length() >= req.limit) {
// Send Uri back to JavaScript for listening to audio
pendingRequests.resolveWithSuccess(req);
} else {
// still need to capture more audio clips
captureAudio(req);
}
}