Adding release method to Media object

This commit is contained in:
macdonst 2010-12-23 02:43:11 +08:00
parent 43c72e684c
commit 2504db13d7
2 changed files with 26 additions and 1 deletions

View File

@ -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]);
};

View File

@ -77,6 +77,10 @@ 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();
@ -118,6 +122,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.
*