这是一个视频录制应用程序,我正在使用它,并且将其上传到数组中的Firebase之后,然后将其记录在console.log中。 我是React Hooks的新手,并且真的很感谢您的帮助!
I have been unable to destructure this, I need the uri values in separate variable so it can be outputted in a <Video/>
component within a <FlatList/>
.
这是需要解构的数组: 注意:为简化起见,我在此处更改了key / uri值。
Array [
Array [
Object {
"key": "0001",
"video": Object {
"uri": "file:///var/mobile/Containers/Data/Application/...",
},
},
Object {
"key": "0002",
"video": Object {
"uri": "file:///var/mobile/Containers/Data/Application/...",
},
},
],
]
Here is what I tried...
const values = videoArray.uir;
console.log("uirs",values);
下面是所有代码: 注意:我已经注释掉Flatlist,但是我希望uri在此处输出...
import React, { useState, useEffect } from 'react'
import { FlatList, View, TouchableOpacity, Text, StyleSheet, SafeAreaView } from 'react-native';
import { Center } from '../components/Center'
import { Video } from 'expo-av';
import firebase from '../firebase'
const videoRef = firebase.database().ref('videoCollaction');
export const FeedScreen = ({ }) => {
var [videoArray, setVideo] = useState([]);
useEffect(() => {
const videoArray = []; // temp array
videoRef.on("value", childSnapshot => {
childSnapshot.forEach(doc => {
videoArray.push({
key: doc.key,
video: doc.toJSON().video
});
});
setVideo(videoArray); // update state array
});
}, []);
// useEffect(() => {
// videoRef.on('value', (childSnapshot) => {
// videoArray = [];
// childSnapshot.forEach((doc) => {
// videoArray.push({
// key: doc.key,
// video: doc.toJSON().video,
// });
// })
// })
// // able to log values only here
// console.log('working:', videoArray);
// });
// get video uri from firebase
// readVideo = () => {
// var collection = firebase.database().ref("videoCollactionvideo" + "/video").orderByValue();
// console.log('uri', collection);
// }
//get uri value from videoArray array...
const values = videoArray.uir;
return (
<SafeAreaView>
<Text>Feed Screen</Text>
//log uir only
{console.log("uirs",values)}
{/* array values here */}
{console.log(" display Array",[videoArray])}
{/* <FlatList
data={[videoArray]}
renderItem={({ item, index }) => {
return (
<View>
<Text style={{ fontSize: 35, color: 'red' }}>Video: {item.uri}</Text>
<TouchableOpacity onPress={() => console.log('pressed')}><Text style={{ color: 'blue' }}>Expand</Text></TouchableOpacity>
</View>
);
}} keyExtractor={({ item }, index) => index.toString()}>
</FlatList> */}
<Video
source={{ uri: {videoArray} }}
// shouldPlay={this.state.shouldPlay}
// isMuted={this.state.mute}
resizeMode="cover"
style={{ width: 300, height: 300 }}
useNativeControls={true}
isLooping={true}
/>
</SafeAreaView>
);
}
不确定为什么如此复杂,将不胜感激。