Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/android/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void onDestroy() {
onLastPlayerReleased();
}
for (AudioPlayer audio : this.players.values()) {
audio.destroy();
audio.onHandlerDestroyed();
}
this.players.clear();
}
Expand Down Expand Up @@ -273,7 +273,7 @@ private boolean release(String id) {
if (players.isEmpty()) {
onLastPlayerReleased();
}
audio.destroy();
audio.destroy(true);
return true;
}

Expand Down
24 changes: 18 additions & 6 deletions src/android/AudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,18 @@ private String generateTempFile() {

/**
* Destroy player and stop audio playing or recording.
* @param broadcastStateChange - if false, setting the state of this oject will not send a status change to the client.
*/
public void destroy() {
public void destroy(boolean broadcastStateChange) {
// Stop any play or record
if (this.player != null) {
if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) {
this.player.stop();
this.player.stop();
}
if (broadcastStateChange) {
this.setState(STATE.MEDIA_STOPPED);
} else { // Do not call the success callback.
this.state = STATE.MEDIA_STOPPED;
}
this.player.release();
this.player = null;
Expand Down Expand Up @@ -522,19 +527,26 @@ public boolean onError(MediaPlayer player, int arg1, int arg2) {
LOG.d(LOG_TAG, "AudioPlayer.onError(" + arg1 + ", " + arg2 + ")");

// we don't want to send success callback
// so we don't call setState() here
this.state = STATE.MEDIA_STOPPED;
this.destroy();
this.destroy(false);
// Send error notification to JavaScript
sendErrorStatus(arg1);

return false;
}

/**
* Lifecyle method called by handler whenever it has been destroyed.
*/
public void onHandlerDestroyed() {
destroy(false);
sendErrorStatus(MEDIA_ERR_ABORTED);
}

/**
* Set the state and send it to JavaScript.
*
* @param state
* @param state - state to transition to

*/
private void setState(STATE state) {
if (this.state != state) {
Expand Down