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

[Android] Playing local files #125

Closed
hunteredwards opened this issue Jan 8, 2016 · 14 comments
Closed

[Android] Playing local files #125

hunteredwards opened this issue Jan 8, 2016 · 14 comments

Comments

@hunteredwards
Copy link

I have tried this: <Video source={{uri: "/storage/emulated/0/test.mp4" }} .... to no avail, and I was wondering if anyone has had any success playing local files on Android. If so, I would like to know how or if this is currently only available for iOS.

@buhe Is your pull request trying to fix this?

Thanks.

@buhe
Copy link

buhe commented Jan 8, 2016

yes !

@isair
Copy link
Contributor

isair commented Jan 8, 2016

Try putting your video file in your Android raw sources folder and then using it as <Video source={{ uri: 'test' }} />. I will keep this issue open until the README is updated to state this.

@hunteredwards
Copy link
Author

@isair the requirement is for playback on video found within the external storage directory, not assets compiled with the app. Basically, the functionality should mimic playback like found with the Gallery app.

@buhe do you have a working example of playing back an external resource?

Additionally, has anyone been able to play locally stored videos on either iOS or Android?

@hunteredwards
Copy link
Author

I figured it out. This function adds the prefix file:// to the uri. On both platforms, commenting this out and having the absolute path without the file:// causes the playback for a local file to work as intended. Maybe a bug?

@buhe
Copy link

buhe commented Jan 9, 2016

Android is ok after comment this , but don't luck at iOS.
My case is I download some online video and cache it ,user don't need download again next playback.

@hunteredwards
Copy link
Author

@isair since you've added a good amount of the android support, I was wondering if you have managed to get remote URLs to play? I haven't had any success thus far. Any help would be greatly appreciated. Thanks.

@buhe
Copy link

buhe commented Jan 11, 2016

@hunteredwards you can try my fork to play external storage video.
I am not android expert, so this fork maybe not unstable..but it is meet my requirement.
"react-native-video": "git://github.com/buhe/react-native-video.git#d872933"

@ghost
Copy link

ghost commented Aug 15, 2016

When I created Lumpen Radio iOS app using this module a year ago I was able to store local video files under the project root folder in src/assets/videos. I was happy with this as I envisioned one day being able to leverage the same location for Android.

During the Android support addition @isair mentioned video files for Android can be stored under android/app/src/main/res/raw/. While I'm extremely grateful for the Android support, the location specified seems less than ideal as it lends itself to duplication of video assets by platform.

Poking through the open PRs I noticed this promising gem, which appears to allow one to leverage the RN asset system to do the resolving and help prevent by-platform file duplication or any kind of funky "cross-the-streams" loading of files for iOS from the Android raw sources folder.

Keywords
storage location where to store android video

Related issues
#246

@ghost
Copy link

ghost commented Aug 16, 2016

See #251 for loading local files using RN assets system.

@tadeaspetak
Copy link

Has anyone figured out how to load anything from /storage/emulated/0... on Android? I have tried a bunch of things (commenting out adding the file:// and updating the Java class to use FileInputStream when setting src) but to no avail... cheers a ton in advance!

@valerybodak
Copy link

valerybodak commented Jun 5, 2017

@tadeaspetak
Did you resolve issue with load anything from /storage/emulated/0...
?

@pqminh
Copy link

pqminh commented Sep 13, 2018

Did anyone resolve issue?

@bd-arc
Copy link

bd-arc commented Feb 6, 2020

For anyone stumbling upon this issue while trying to load local videos (i.e. native project assets rather than RN static resources), I have a few tips.

In my case, it was a matter of saving precious megabytes for CodePush updates. Indeed, when the videos are part of the RN project's static resources, they will be included in the JS bundle sent to CodePush and retrieved by the users. I'll let you do the calculation, but when you save more than 30 MB per update times 50k users, that counts! Not to mention the enhanced user experience.

To do so, you'll first need to add the video files to your project:

  • Android: Save your mp4 files under the directory android/app/src/main/res/raw. Note that files in this directory must be lowercase and underscored (e.g. my_video.mp4) and that subdirectories are not supported by Android.
  • iOS: Open Xcode and add your mp4 files to the project (right-click the project and select "Add Files to [PROJECTNAME]"). Subdirectories are supported by iOS.

Then for the tricky part that cost me a lot of trials and errors:

  • Android: use the filename as the uri but don't specify the file extension.
    • Example: <Video source={{ uri: 'my_video' }} />
  • iOS: it's the exact opposite, meaning you need to specify the file extension.
    • Example: <Video source={{ uri: 'my_video.mp4' }} />

I didn't find this info anywhere so I thought it could help a frustrated dev or two ;-)

@ZeeshanAhmadKhalil
Copy link

For anyone stumbling upon this issue while trying to load local videos (i.e. native project assets rather than RN static resources), I have a few tips.

In my case, it was a matter of saving previous megabytes for CodePush updates. Indeed, when the videos are part of the RN project's static resources, they will be included in the JS bundle sent to CodePush and retrieved by the users. I'll let you do the calculation, but when you save more than 30 MB per update times 50k users, that counts! Not to mention the enhanced user experience.

To do so, you'll first need to add the video files to your project:

  • Android: Save your mp4 files under the directory android/app/src/main/res/raw. Note that files in this directory must be lowercase and underscored (e.g. my_video.mp4) and that subdirectories are not supported by Android.
  • iOS: Open Xcode and add your mp4 files to the project (right-click the project and select "Add Files to [PROJECTNAME]"). Subdirectories are supported by iOS.

Then for the tricky part that cost me a lot of trials and errors:

  • Android: use the filename as the uri but don't specify the file extension.

    • Example: <Video source={{ uri: 'my_video' }} />
  • iOS: it's the exact opposite, meaning you need to specify the file extension.

    • Example: <Video source={{ uri: 'my_video.mp4' }} />

I didn't find this info anywhere so I thought it could help a frustrated dev or two ;-)

How we can download file in android/app/src/main/res/raw

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

8 participants