【发布时间】:2020-07-15 22:32:28
【问题描述】:
我正在尝试使用适用于 React 本机的 cameraRoll 库打印每个视频的总持续时间和视频大小,但它对所有视频都显示为空。 这可以修复吗,所以我可以显示每个视频的总时长和视频大小。
CameraRoll 库链接https://github.com/react-native-community/react-native-cameraroll
export default class camera extends Component {
constructor(props) {
super(props);
this.state = {
data:''
};
}
async componentDidMount()
{
if (Platform.OS === 'android') {
const result = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: 'Permission Explanation',
message: 'ReactNativeForYou would like to access your photos!',
},
);
if (result !== 'granted') {
console.log('Access to pictures was denied');
return;
}
}
CameraRoll.getPhotos({
first: 3,
assetType: 'Videos',
})
.then(res => {
this.setState({
data: res.edges,
});
})
.catch((error) => {
console.log(error);
});
}
render() {
return (
<View style={{flex: 1, flexDirection: 'row'}}>
<FlatList
data={this.state.data}
numColumns={1}
renderItem={({ item }) =>
<View
style={{ flexDirection: 'row',}}
>
<Video
ref={(ref) => {
this.player = ref
}}
source={{ uri: item.node.image.uri }}
onBuffer={this.onBuffer}
onError={this.videoError}
resizeMode='cover'
repeat={true}
muted={true}
playWhenInactive={true}
style={{
width: '30%',
height: 80,
marginLeft:10,
marginTop:10,
borderRadius:10,
}}
/>
<Text
style={{textAlign: 'center', alignSelf: 'stretch', textAlignVertical: 'center',
paddingLeft: 30, overflow: "hidden", }}
>{JSON.stringify(item.node.image.fileSize)} // this line should have displayed the video file size
</Text>
<Text
style={{textAlign: 'center', alignSelf: 'stretch', textAlignVertical: 'center',
paddingLeft: 30, overflow: "hidden", }}
>{item.node.image.playableDuration} //This line should have displayed the video duration
</Text>
</View>
}
/>
</View>
);
}
}
这是我的完整代码。
【问题讨论】:
标签: reactjs react-native react-native-android react-native-camera react-native-video