Skip to content

Commit

Permalink
Merge pull request #272 from macdonst/mediaErr
Browse files Browse the repository at this point in the history
Media err normalization with iOS
  • Loading branch information
macdonst committed Oct 19, 2011
2 parents 7ee04eb + 551f0f7 commit 1f2f9a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
3 changes: 2 additions & 1 deletion framework/assets/js/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var MediaError = function() {
this.message = "";
};

MediaError.MEDIA_ERR_NONE_ACTIVE = 0;
MediaError.MEDIA_ERR_ABORTED = 1;
MediaError.MEDIA_ERR_NETWORK = 2;
MediaError.MEDIA_ERR_DECODE = 3;
Expand Down Expand Up @@ -211,7 +212,7 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
}
else if (msg === Media.MEDIA_ERROR) {
if (media.errorCallback) {
media.errorCallback(value);
media.errorCallback({"code":value});
}
}
else if (msg == Media.MEDIA_POSITION) {
Expand Down
33 changes: 15 additions & 18 deletions framework/src/com/phonegap/AudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
private static int MEDIA_POSITION = 3;
private static int MEDIA_ERROR = 9;

// AudioPlayer error codes
private static int MEDIA_ERROR_PLAY_MODE_SET = 1;
private static int MEDIA_ERROR_ALREADY_RECORDING = 2;
private static int MEDIA_ERROR_STARTING_RECORDING = 3;
private static int MEDIA_ERROR_RECORD_MODE_SET = 4;
private static int MEDIA_ERROR_STARTING_PLAYBACK = 5;
private static int MEDIA_ERROR_RESUME_STATE = 6;
private static int MEDIA_ERROR_PAUSE_STATE = 7;
private static int MEDIA_ERROR_STOP_STATE = 8;

// Media error codes
private static int MEDIA_ERR_NONE_ACTIVE = 0;
private static int MEDIA_ERR_ABORTED = 1;
private static int MEDIA_ERR_NETWORK = 2;
private static int MEDIA_ERR_DECODE = 3;
private static int MEDIA_ERR_NONE_SUPPORTED = 4;

private AudioHandler handler; // The AudioHandler object
private String id; // The id of this player (used to identify Media object in JavaScript)
private int state = MEDIA_NONE; // State of recording or playback
Expand Down Expand Up @@ -108,7 +105,7 @@ public void destroy() {
public void startRecording(String file) {
if (this.mPlayer != null) {
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PLAY_MODE_SET+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}

// Make sure we're not already recording
Expand All @@ -129,11 +126,11 @@ else if (this.recorder == null) {
} catch (IOException e) {
e.printStackTrace();
}
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_RECORDING+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}
else {
Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_ALREADY_RECORDING+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}
}

Expand Down Expand Up @@ -175,7 +172,7 @@ public void stopRecording() {
public void startPlaying(String file) {
if (this.recorder != null) {
Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RECORD_MODE_SET+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}

// If this is a new request to play audio, or stopped
Expand Down Expand Up @@ -220,7 +217,7 @@ else if ((this.mPlayer == null) || (this.state == MEDIA_STOPPED)) {
}
catch (Exception e) {
e.printStackTrace();
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STARTING_PLAYBACK+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}
}

Expand All @@ -234,7 +231,7 @@ else if ((this.mPlayer == null) || (this.state == MEDIA_STOPPED)) {
}
else {
Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_RESUME_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
}
}
}
Expand Down Expand Up @@ -262,7 +259,7 @@ public void pausePlaying() {
}
else {
Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_PAUSE_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
}
}

Expand All @@ -276,7 +273,7 @@ public void stopPlaying() {
}
else {
Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERROR_STOP_STATE+");");
this.handler.sendJavascript("PhoneGap.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
}
}

Expand Down

0 comments on commit 1f2f9a0

Please sign in to comment.