CB-5517 Fix the audio capture IO exception by putting it in a runnable https://github.com/apache/cordova-plugin-media-capture/pull/10
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/7184efe7 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/7184efe7 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/7184efe7 Branch: refs/heads/master Commit: 7184efe7a00b13ca4b10938932a2092009818103 Parents: 09d74fe Author: Jeff Sawatzky <[email protected]> Authored: Mon Dec 9 13:59:45 2013 -0500 Committer: Andrew Grieve <[email protected]> Committed: Mon Dec 9 15:05:48 2013 -0500 ---------------------------------------------------------------------- src/android/Capture.java | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/7184efe7/src/android/Capture.java ---------------------------------------------------------------------- diff --git a/src/android/Capture.java b/src/android/Capture.java index 9cfa9b9..2318a06 100644 --- a/src/android/Capture.java +++ b/src/android/Capture.java @@ -259,18 +259,27 @@ public class Capture extends CordovaPlugin { if (resultCode == Activity.RESULT_OK) { // An audio clip was requested if (requestCode == CAPTURE_AUDIO) { - // Get the uri of the audio clip - Uri data = intent.getData(); - // create a file object from the uri - results.put(createMediaFile(data)); - - if (results.length() >= limit) { - // Send Uri back to JavaScript for listening to audio - this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results)); - } else { - // still need to capture more audio clips - captureAudio(); - } + + final Capture that = this; + Runnable captureAudio = new Runnable() { + + @Override + public void run() { + // Get the uri of the audio clip + Uri data = intent.getData(); + // create a file object from the uri + results.put(createMediaFile(data)); + + if (results.length() >= limit) { + // Send Uri back to JavaScript for listening to audio + that.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results)); + } else { + // still need to capture more audio clips + captureAudio(); + } + } + }; + this.cordova.getThreadPool().execute(captureAudio); } else if (requestCode == CAPTURE_IMAGE) { // For some reason if I try to do: // Uri data = intent.getData(); @@ -331,10 +340,10 @@ public class Capture extends CordovaPlugin { }; this.cordova.getThreadPool().execute(captureImage); } else if (requestCode == CAPTURE_VIDEO) { - + final Capture that = this; Runnable captureVideo = new Runnable() { - + @Override public void run() { // Get the uri of the video clip
