Best Practice for Downloading Videos, Storing File Locally, and Playing In App?

@notbrent I saw you on this repo/thread and was wondering if you (or others) had suggestions for downloading videos to be viewed offline, preferably inside the app.

Is it possible to use the Asset API for this?

Update:

Looks like you’ll need react-native-fetch-blob:

http://stackoverflow.com/questions/42584718/how-to-download-and-retrieve-local-files-on-ios-with-react-native-and-react-nati?rq=1

hmm seeing this now too GitHub - expo/exponent-react-native-fs: Native filesystem access for react-native, exponent version. Based on https://github.com/johanneslumpe/react-native-fs

2 Likes

@arcomito I was looking to do the same thing as you!

Here’s a workaround for now:
https://github.com/florentroques/expo-download-and-play-video-example/blob/master/enhancedAsset.js#L26-L92
(working with current Expo SDK 18, before any FileSystem API improvement/change)

How to use this workaround function:
https://github.com/florentroques/expo-download-and-play-video-example/blob/master/App.js#L23-L53

It uses the undocumented FileSystem API behind the Asset API (inspired by @astonm’s code i found on github which put me on the way)

The issue was that with the downloadAsync function in Asset, you need the md5 hash of the file beforehand. But with a remote file, you don’t have it by default, unless you calculated it before!
So i created a downloadAsync alternative version without hash.

Expo demo app: https://expo.io/@florentroques/expo-download-and-play-video
Demo app’s code: https://github.com/florentroques/expo-download-and-play-video-example

I’m open to any improvement, suggestion etc!

3 Likes

Some websites can also help you to download videos online, such as keepvid, catchvideo, videograby, etc.
You can find many sites for downloading videos and their information there: The Best Sites to Download Videos and Music Efforlessly. It;s a good method to play the videos you like offline.