Use Local Files or Remote Video Files with React Native Video

Jason Brown
InstructorJason Brown
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

In this lesson we'll show the different methods that react-native-video allows to play video including remote video files as well as local files imported as asset files by React Native.

We'll also show you a couple properties you can use on your <Video/> component to resize and add some styles!

React Native video supports MP4s from remote and also from the local file system using the React Native asset system. To use that, we can add an MP4 anywhere within our directory. We have one here called lights.mp4.

We can use require or we can also use import. We'll import light video from ./lights.mp4. Then to use it with our React Native video component we type video and pass it in as the source.

To use remote videos, we'll need to use a object here rather than a import and type URI and then pass in the string of the MP4 that you want to use. It's important to note that we import the video before we start our build, because there's a special build process script that runs when you start up the packager.

If we go back to our Xcode and now we start our build, the packager will start up, iOS Simulator will also start up and our video will be included in the asset system.

Now that we have our simulator started up, we can show off the video actually working. First, we'll switch this back to use the light video that we imported. We will add a resize mode of cover, then also add the style and use the styleSheet.absoluteFill to cover the entire thing.

Now that we have refreshed, we can see that our video is automatically playing and it is covering the entire screen. We can then also switch this back to our URI, save it, refresh, and also see that our video is playing from a remote source.

egghead
egghead
~ 23 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today