Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to load video from android_asset #379

Closed
lee11qian opened this issue Nov 15, 2016 · 3 comments
Closed

how to load video from android_asset #379

lee11qian opened this issue Nov 15, 2016 · 3 comments

Comments

@lee11qian
Copy link

lee11qian commented Nov 15, 2016

react-native-cli: 1.0.0
react-native: 0.36.0
react-native-video: 0.9.0

i want to use like this:

<Video source={{uri: 'file:///android_asset/source/64.mp3'}} .../>

but logcat tell me:

Failed to open file '/android_asset/source/64.mp3'. (No such file or directory)

I guarantee that the file exists.

Can't it be used in this way.

I hope someone tell me how to do.

@prananta
Copy link

I might be wrong, but according to this SO

MediaPlayer expects an URI and it's impossible to create an URI for an assets file

Seems like you need to use AssetManager to get file descriptor to the video file and set it as datasource for MediaPlayer. But if you look at the file ReactVideoView.java, it doesn't support it.

So maybe not possible to load from android_asset. You could however just use React Native asset system as mentioned in the Readme.

Or pull request? 😄

@lee11qian
Copy link
Author

lee11qian commented Nov 17, 2016

Thank you for tell me this. But my project must use file from android_asset. So i change the file ReactVideoView.java like this:

if (uriString.startsWith("content://")) {
    Uri parsedUrl = Uri.parse(uriString);
    setDataSource(mThemedReactContext, parsedUrl);
} else if (uriString.startsWith("file:///android_asset")) {    // <----- add begin
    AssetFileDescriptor afd = getResources().getAssets().openFd(uriString.replace("file:///android_asset/", ""));
    mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
    mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), null);
    prepareAsync(this);
    return;                    // <----- add end
} else {
    setDataSource(uriString);
}

Is it any errors? I just use it in my project now.

@afilp
Copy link

afilp commented May 27, 2020

Does this still work? Can this be a PR and merged?
I also need to use uri: 'file:///android_asset/ because the videos are large and the code-push would delay a lot.

How can we do this now? In 2020?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants