首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用react-native-image-picker显示视频

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

Stack Overflow用户
提问于 2017-10-16 23:19:35
回答 2查看 7.2K关注 0票数 2

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

代码语言:javascript
复制
const options = {
      title: 'Video Picker', 
      mediaType: 'video', 
      storageOptions:{
        skipBackup:true,
        path:'images'
      }
};

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

EN

回答 2

Stack Overflow用户

发布于 2019-08-29 17:34:39

代码语言:javascript
复制
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>

);
}



}
票数 2
EN

Stack Overflow用户

发布于 2017-10-16 23:34:06

您可以使用this package并将从图像拾取器中检索到的uri传递给它,如下所示:

代码语言:javascript
复制
ImagePicker.launchCamera(options, (response)  => {
    const uri = response.uri
});

示例:

代码语言:javascript
复制
ImagePicker.launchCamera(options, (response)  => {
    const uri = response.uri
    this.setState({ uri })
});

 ...

<View style={{ flex: 1 }}>
   <Video source={{uri: this.state.uri}}
</View>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46773659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档