Skip to content
Open
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
48 changes: 28 additions & 20 deletions src/android/AudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,35 +521,43 @@ private void loadAudioFile(String file) throws IllegalArgumentException, Securit
if (this.isStreaming(file)) {
this.player.setDataSource(file);
this.player.setAudioStreamType(AudioManager.STREAM_MUSIC);
//if it's a streaming file, play mode is implied
// If it's a streaming file, play mode is implied.
this.setMode(MODE.PLAY);
this.setState(STATE.MEDIA_STARTING);
this.player.setOnPreparedListener(this);
this.player.prepareAsync();
return;
}
else {
if (file.startsWith("/android_asset/")) {
String f = file.substring(15);
android.content.res.AssetFileDescriptor fd = this.handler.cordova.getActivity().getAssets().openFd(f);
this.player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
}
else {
File fp = new File(file);
if (file.startsWith("/android_asset/")) {
String f = file.substring(15);
android.content.res.AssetFileDescriptor fd = this.handler.cordova.getActivity().getAssets().openFd(f);
this.player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
} else {
File fp = new File(file);
if (fp.exists()) {
FileInputStream fileInputStream = new FileInputStream(file);
this.player.setDataSource(fileInputStream.getFD());
fileInputStream.close();
} else {
String original_file = file;
file = Environment.getExternalStorageDirectory().getPath() + "/" + file;
// If the new file exists, set it as the data source.
// In case the file still doesn't exist, try the original method again.
fp = new File(file);
if (fp.exists()) {
FileInputStream fileInputStream = new FileInputStream(file);
this.player.setDataSource(file);
} else {
FileInputStream fileInputStream = new FileInputStream(original_file);
this.player.setDataSource(fileInputStream.getFD());
fileInputStream.close();
}
else {
this.player.setDataSource(Environment.getExternalStorageDirectory().getPath() + "/" + file);
}
}
this.setState(STATE.MEDIA_STARTING);
this.player.setOnPreparedListener(this);
this.player.prepare();

// Get duration
this.duration = getDurationInSeconds();
}
}
this.setState(STATE.MEDIA_STARTING);
this.player.setOnPreparedListener(this);
this.player.prepare();

// Get duration.
this.duration = getDurationInSeconds();
}
}