如何使用REACT-NATIVE-IMAGE-PICKER从库中选择视频?

时间:2017-08-25 04:45:25

标签: react-native

我完美选择了图片,但我无法选择视频, 我需要做什么?

从'react-native-image-picker'导入ImagePicker;

openImagePicker(){
  const options = {
    title:'select an option',

    storageOptions:{
      skipBackup:true,
      path:'images'
    }
  }
  ImagePicker.showImagePicker(options,(response) => {
    if(response.didCancel){
      console.log('user cancelled');
    }else if (response.error) {
      console.log('ERROR'+response.error);

    }else if (response.customButton) {
      console.log('user tapped'+response.customButton);
    }else {
      this.setState({
        imagePath: response.uri,
        imageHeight: response.height,
        imageWidth: response.width
      })
    }


  })

  }

3 个答案:

答案 0 :(得分:4)

尝试在options上添加mediaType

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

答案 1 :(得分:0)

添加(mediaType:'视频')仅允许您选择视频,这是正确的,因为我希望能够同时选择图像

答案 2 :(得分:0)

如果要使用视频和图像文件格式而不是使用将mediaType更改为

const options = {
      title: 'Video Picker', 
      mediaType: 'image/video', 
      ..
};

OR

const options = {
      title: 'Video Picker', 
      mediaType: 'any', 
      ..
};