gpt4 book ai didi

javascript - 如何解决错误 - 尝试在 react native 视频中加载空源

转载 作者:行者123 更新时间:2023-12-05 06:03:25 25 4
gpt4 key购买 nike

我尝试使用视频作为配置文件切换器,这样当按下配置文件切换器时,它会在另一个屏幕中播放视频。但我试过播放它保留的视频给我一个警告“试图加载空源”。请问我错过了什么?

这是我在 videoAvarterScreen.js 上的代码:

...
import vidData from '../../../data/data';
import Video from 'react-native-video';
import styles from './styles';

const VideoAvarterScreen = () => {


const route = useRoute();

const userId = route.params.userId;

const userAvarter = vidData.find(vidAvarter => vidAvarter.user.id === userId);

console.log("userAvarter");
console.log(userAvarter);



const [paused, setPaused] = useState(true);

const onPlayPausePress = () => {
setPaused(!paused);
}

return(
<SafeAreaView style={styles.container}>
<TouchableOpacity onPress={onPlayPausePress}>
<Video
source={{ uri: vidData.videoUri }}
style={styles.videoAvarter}
resizeMode={'cover'}
repeat={true}
paused={paused}
/>
</TouchableOpacity>

</SafeAreaView>
);
}

export default VideoAvarterScreen;

这是我的 data.js:

export default [
{
id: '1',
user: {
imageUri: 'https://media-exp1.licdn.com/dms/image/C4D03AQEh5M1sg1G5VA/profile-displayphoto-shrink_800_800/0/1516536139756?e=1613606400&v=beta&t=xKHlgicMaGaMAxW_L6f83Tvt3o-tbDGbUjtzyYRf9Qk',
name: 'Shawacademy',
username: '@shawacademy',
gender: 'female',
bio: `I'm an entrepreneur, and \nambitous business woman.`
},

videoAvarter: [
{
videoUri: 'https://www.w3schools.com/html/mov_bbb.mp4',
postedAt: '30 minutes ago',
locatedAt: 'Kuwait, Kuwait',
}
]

},
......

最佳答案

您的视频组件使用原始 vidData 数组而不是 userAvarter 值。

因此尝试将 source={{ uri: vidData.videoUri }} 更改为source={{ uri: userAvarter.videoAvarter.videoUri }}

关于javascript - 如何解决错误 - 尝试在 react native 视频中加载空源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66648972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com