react-native - 如何在 expo-av react native 中使用本地 mp4 文件
问题描述
我已将其全部设置为加载 uri,它与 expo 文档中的示例基本完全相同。我不知道如何改用我的本地文件系统。我的文件系统中有 mp4,但是当我将路径链接到文件系统时,屏幕变为空白,没有任何显示。我将包含我正在使用但似乎无法使其工作的代码片段
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,
},
});
解决方案
文档中没有提到videoURL
位,所以只需放下它,您就会看到视频:
source={require("../assets/videos/TestVideo.mp4")}
推荐阅读
- c++ - 使用共享指针实现单例的正确方法?
- python - 发生异常:错误 mpg123_seek:无效的 RVA 模式。(代码 12)
- rust - 为什么这个 Rust 错误消息谈论数据“流动”?
- c++ - Lambda 函数给出了意外的输出
- vega-lite - 如何在 vega 公式变换中使用阶乘(!)
- javascript - 如何在 v-data-iterator 中获取自定义插槽?
- c++ - 如何正确使用 std::cin.get() 和 std::cin.peek() 的返回值?
- php - 检查用户是否经过身份验证或没有@Guest 的访客
- .net - Dockerfile复制功能与.NET发布交互
- c# - 如何在接口 IProlongable(存款)中实现 CanToProlong 方法?