3

I'm using react-native-ImagePicker for selecting video's from my phone . so i used the below code ,

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

The problem here is i can able to record/Select the video , i cant able to show that inside a <View> . I searched many sites and almost spend 5 hours in this but still am not able to find the solution for that . Can someone help/clarify me from this . Code reference from this git_hub site .

Beckham_Vinoth
  • 701
  • 2
  • 13
  • 39

2 Answers2

2
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>

);
}



}
Bhargav Patel
  • 85
  • 1
  • 12
1

You can use this package and pass it the uri which you retrieve from image picker like so:

ImagePicker.launchCamera(options, (response)  => {
    const uri = response.uri
});

Example:

ImagePicker.launchCamera(options, (response)  => {
    const uri = response.uri
    this.setState({ uri })
});

 ...

<View style={{ flex: 1 }}>
   <Video source={{uri: this.state.uri}}
</View>
Alexander Vitanov
  • 4,074
  • 2
  • 19
  • 22