How to use local mp4 file in expo-av react native

Viewed 1525

I have it all set up to load a uri its basically the exact same as the example in the expo docs. I cant figure out how to use my local file system instead. I have the mp4 in my file system but when I link the path to the file system the screen goes blank and nothing shows. I'll include the snippet of code that I'm using but can't seem to get it to work

import * as React from "react";
import { View, StyleSheet, Button } from "react-native";
import { Video, AVPlaybackStatus } from "expo-av";

export default function App() {
  const video = React.useRef(null);
  const [status, setStatus] = React.useState({});
  return (
    <View style={styles.container}>
      <Video
        ref={video}
        style={styles.video}
        source={{
          videoURL: require("../assets/videos/TestVideo.mp4"),
        }}
        useNativeControls
        resizeMode="contain"
        isLooping
        onPlaybackStatusUpdate={(status) => setStatus(() => status)}
      />
      <View style={styles.buttons}>
        <Button
          title={status.isPlaying ? "Pause" : "Play"}
          onPress={() =>
            status.isPlaying
              ? video.current.pauseAsync()
              : video.current.playAsync()
          }
        />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  video: {
    flex: 1,
  },
});

1 Answers

There is no mention of videoURL bit in the docs so just drop it and you'll see the video:

source={require("../assets/videos/TestVideo.mp4")}
Related