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]); 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,13 +77,17 @@ public class AudioHandler extends Plugin {
long l = this.getDurationAudio(args.getString(0), args.getString(1)); long l = this.getDurationAudio(args.getString(0), args.getString(1));
return new PluginResult(status, l); 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); return new PluginResult(status, result);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
return new PluginResult(PluginResult.Status.JSON_EXCEPTION); return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
} }
} }
/** /**
* Identifies if action to be executed returns a value and should be run synchronously. * 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 // 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. * Start recording and save the specified file.