React native 如何在expo av react native中使用本地mp4文件
我已经设置好加载uri,基本上与expo文档中的示例完全相同。我不知道如何使用我的本地文件系统。我的文件系统中有mp4,但当我将路径链接到文件系统时,屏幕变为空白,没有显示任何内容。我将包括我正在使用的代码片段,但它似乎无法正常工作React native 如何在expo av react native中使用本地mp4文件,react-native,expo,React Native,Expo,我已经设置好加载uri,基本上与expo文档中的示例完全相同。我不知道如何使用我的本地文件系统。我的文件系统中有mp4,但当我将路径链接到文件系统时,屏幕变为空白,没有显示任何内容。我将包括我正在使用的代码片段,但它似乎无法正常工作 import * as React from "react"; import { View, StyleSheet, Button } from "react-native"; import { Video, AVPlayba
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,
},
});
import*as React from“React”;
从“react native”导入{视图、样式表、按钮};
从“expo av”导入{Video,AVPlaybackStatus};
导出默认函数App(){
const video=React.useRef(null);
const[status,setStatus]=React.useState({});
返回(
设置状态(()=>状态)}
/>
状态显示
?video.current.pauseAsync()
:video.current.playsync()
}
/>
);
}
const styles=StyleSheet.create({
容器:{
弹性:1,
},
视频:{
弹性:1,
},
});
中没有提到videoURL
位,因此只要放下它,您就会看到视频:
source={require(../assets/videos/TestVideo.mp4”)}
这是一个完美的解决方案,谢谢