gpt4 book ai didi

react-native - 如何使用 react-native-image-picker 显示视频

转载 作者:行者123 更新时间:2023-12-05 04:09:02 24 4
gpt4 key购买 nike

我正在使用 react-native-ImagePicker用于从我的手机中选择视频。所以我使用了下面的代码,

const options = {
title: 'Video Picker',
mediaType: 'video',
storageOptions:{
skipBackup:true,
path:'images'
}
};

这里的问题是我可以录制/选择视频,我无法在 <View> 中显示它.我搜索了很多网站,几乎花了 5 个小时,但仍然找不到解决方案。有人可以帮我澄清一下吗?代码引用来自 this git_hub网站。

最佳答案

import ImagePicker from 'react-native-image-picker';
import Video from 'react-native-video';

class MyComponent extends Component{

constructor(props){
super(props);

this.state = {
videoSource:'',
};
}

const options2 = {
title: 'Select video',
mediaType: 'video',
path:'video',
quality: 1
};


selectVideo = () => {


ImagePicker.showImagePicker(options2, (response) => {
console.log('Response = ', response);

if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };


this.setState({videoSource: source})


}
});


}

render(){
return(

<View>

<Video source={this.state.videoSource} // Can be a URL or a local file.
ref={(ref) => {
this.player = ref
}} // Store reference
onBuffer={this.onBuffer} // Callback when remote video is buffering
onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
controls={true}
fullscreen={true}
style={styles.uploadImage} />


<Button small primary onPress={this.selectVideo}>
<Text>Select Video</Text>
</Button>



</View>

);
}



}

关于react-native - 如何使用 react-native-image-picker 显示视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46773659/

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