in src/android/AudioPlayer.java [620:682]
private boolean readyPlayer(String file) {
if (playMode()) {
switch (this.state) {
case MEDIA_NONE:
if (this.player == null) {
this.player = new MediaPlayer();
this.player.setOnErrorListener(this);
}
try {
this.loadAudioFile(file);
} catch (Exception e) {
sendErrorStatus(MEDIA_ERR_ABORTED, e.getMessage());
}
return false;
case MEDIA_LOADING:
//cordova js is not aware of MEDIA_LOADING, so we send MEDIA_STARTING instead
LOG.d(LOG_TAG, "AudioPlayer Loading: startPlaying() called during media preparation: " + STATE.MEDIA_STARTING.ordinal());
this.prepareOnly = false;
return false;
case MEDIA_STARTING:
case MEDIA_RUNNING:
case MEDIA_PAUSED:
return true;
case MEDIA_STOPPED:
//if we are readying the same file
if (file!=null && this.audioFile.compareTo(file) == 0) {
//maybe it was recording?
if (player == null) {
this.player = new MediaPlayer();
this.player.setOnErrorListener(this);
this.prepareOnly = false;
try {
this.loadAudioFile(file);
} catch (Exception e) {
sendErrorStatus(MEDIA_ERR_ABORTED, e.getMessage());
}
return false;//we´re not ready yet
}
else {
//reset the audio file
player.seekTo(0);
player.pause();
return true;
}
} else {
//reset the player
this.player.reset();
try {
this.loadAudioFile(file);
} catch (Exception e) {
sendErrorStatus(MEDIA_ERR_ABORTED, e.getMessage());
}
//if we had to prepare the file, we won't be in the correct state for playback
return false;
}
default:
String errorMessage = "AudioPlayer Error: startPlaying() called during invalid state: " + this.state;
sendErrorStatus(MEDIA_ERR_ABORTED, errorMessage);
}
}
return false;
}