Skip to content

Commit

Permalink
DataSource improvements file:///android_assets and asset://
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenfeld committed Sep 1, 2016
1 parent ca9de7c commit b897b40
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
Expand Down Expand Up @@ -368,6 +369,18 @@ private void prepare() {
(mSource.getScheme().equals("http") || mSource.getScheme().equals("https"))) {
LOG("Loading web URI: " + mSource.toString());
mPlayer.setDataSource(mSource.toString());
} else if (mSource.getScheme() != null && (mSource.getScheme().equals("file") && mSource.getPath().contains("/android_assets/"))) {
LOG("Loading assets URI: " + mSource.toString());
AssetFileDescriptor afd;
afd = getContext().getAssets().openFd(mSource.toString().replace("file:///android_assets/", ""));
mPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} else if (mSource.getScheme() != null && mSource.getScheme().equals("asset")) {
LOG("Loading assets URI: " + mSource.toString());
AssetFileDescriptor afd;
afd = getContext().getAssets().openFd(mSource.toString().replace("asset://", ""));
mPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} else {
LOG("Loading local URI: " + mSource.toString());
mPlayer.setDataSource(getContext(), mSource);
Expand Down

0 comments on commit b897b40

Please sign in to comment.