1
import ImagePicker from 'react-native-image-picker';
   const options = {
      title: 'Select Image',
      takePhotoButtonTitle:'take a photo',
      chooseFromlibraryButtonTitle:'choose from gallery',
      quality:1 
    };

    class Upload extends Component <{}>{
        static navigationOptions = { header: null }

        constructor(){
            super()
            this.state ={
                ImageSource:null
            }
        }
        selectPhoto(){
                    ImagePicker.showImagePicker(options, (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 {
                let source = { uri: response.uri };  
                this.setState({
                  ImageSource: source,
                });
                }
                });
        }
  1. 如何在本机反应中显示带有图像的视频并使用 video soucr uri 状态仍然只显示图像 2.and 如果使用媒体类型仍然显示图像如何解决这个问题
4

2 回答 2

2

您是为 Android/iOS/两者开发吗?看起来您必须mediaType={mixed}为 iOS 指定,并且您必须指定是否要查看 Android 的视频或图像。

于 2018-10-21T23:38:59.583 回答
1

干得好

   ImagePicker.showImagePicker({
        title: 'Choose Image or Video',
        customButtons: [{ name: 'image', title: 'Take a Photo' },{ name: 'video', title: 'Take a Video' }],
        chooseFromLibraryButtonTitle: null,
        takePhotoButtonTitle: null,
    }, (res) => {
        if(res.customButton ){
            ImagePicker.launchCamera({
                mediaType: res.customButton,
                videoQuality: 'high',
                quality: 1,
            }, (response) => {
                // Same code as in above section!
            });
        }
    });
于 2019-05-27T19:56:48.027 回答