diff --git a/framework/assets/js/media.js b/framework/assets/js/media.js index eae033f6..1994708f 100755 --- a/framework/assets/js/media.js +++ b/framework/assets/js/media.js @@ -192,3 +192,10 @@ Media.prototype.stopRecord = function() { PhoneGap.exec(null, null, "Media", "stopRecordingAudio", [this.id]); }; +/** + * Release the resources. + */ +Media.prototype.release = function() { + PhoneGap.exec(null, null, "Media", "release", [this.id]); +}; + diff --git a/framework/src/com/phonegap/AudioHandler.java b/framework/src/com/phonegap/AudioHandler.java index 5e995805..d11f0f98 100755 --- a/framework/src/com/phonegap/AudioHandler.java +++ b/framework/src/com/phonegap/AudioHandler.java @@ -77,13 +77,17 @@ public class AudioHandler extends Plugin { long l = this.getDurationAudio(args.getString(0), args.getString(1)); return new PluginResult(status, l); } + else if (action.equals("release")) { + boolean b = this.release(args.getString(0)); + return new PluginResult(status, b); + } return new PluginResult(status, result); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } } - + /** * Identifies if action to be executed returns a value and should be run synchronously. * @@ -117,6 +121,20 @@ public class AudioHandler extends Plugin { //-------------------------------------------------------------------------- // LOCAL METHODS //-------------------------------------------------------------------------- + + /** + * Release the audio player instance to save memory. + * + * @param id The id of the audio player + */ + private boolean release(String id) { + if (!this.players.containsKey(id)) { + return false; + } + AudioPlayer audio = this.players.get(id); + audio.destroy(); + return true; + } /** * Start recording and save the specified file.