【问题标题】:how to show videos and images with react-native-image-picker in react native如何在 react native 中使用 react-native-image-picker 显示视频和图像
【发布时间】:2018-10-21 23:09:03
【问题描述】:
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. 如何在 React Native 中显示带有图像的视频,并使用 video soucr uri 状态仍然只显示图像 2.如果使用媒体类型,所有仍然显示图像如何解决这个问题

【问题讨论】:

    标签: react-native react-native-image-picker


    【解决方案1】:

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

    【讨论】:

    • 您必须使用两个按钮,一个用于获取照片,一个用于获取视频
    【解决方案2】:

    给你

       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!
                });
            }
        });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多