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

#1

@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:

hmm seeing this now too https://github.com/expo/exponent-react-native-fs

1 Like
#2

@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
#3

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: http://www.videoconverterfactory.com/tips/best-sites-to-download-videos.html. It;s a good method to play the videos you like offline.