1

I'm using react-native-image-picker library for video recording and react-native-video to play video in which duration of video in onLoad callback function is given but how can I use it in my code can anyone please guide me? I have written durationLimit in function but it is not working. How can I record video of duration 30 seconds? I tried this too but failed.

My Code

import ImagePicker from 'react-native-image-picker';   
import Video from 'react-native-video';

constructor(props){
   super(props);
   this.state = {
      video: '',
      isVideo: true
   };
};
_handleVideoUpload = () => {
   const options = {
      mediaType: 'video',
      videoQuality: 'medium',
      durationLimit: 30000,
      thumbnail: true,
      allowsEditing: true,
   };

   ImagePicker.launchCamera(options, (response) => {
      if (response.didCancel) {
        // console.warn('User cancelled video picker');
        return true;
      } else if (response.error) {
         // console.warn('ImagePicker Error: ', response.error);
      } else if (response.customButton) {
          console.warn('User tapped custom button: ', response.customButton);
      } else {
         this.setState({video: response.uri});
      } 
   });
 }

render() {
   return(
     <View>
     {
      this.state.video != '' ?
         <View>                     
           <Video
              ref={ref => this._video = ref}
              source={{ uri: this.state.video }}
              resizeMode={'cover'}
              repeat={true}
              paused = {true}
              onLoad={() => { this._video.seek(2);}} 
           />
       </View>
     : 
       <TouchableOpacity 
          onPress={() => this._handleVideoUpload()}
       >
         <Text>Upload Video</Text>
      </TouchableOpacity>
    }
   </View>
);}

Thank you in advance.

Riddhi
  • 755
  • 11
  • 31

1 Answers1

3

If you want to record a video of 30 seconds you need tu put 30 in durationLimit, not 30000

`const options = {
   mediaType: 'video',
   videoQuality: 'medium',
   durationLimit: 30,
   thumbnail: true,
   allowsEditing: true,
};`

If you want to know the duration time if video on <Video /> you can do that:

`_onLoad(data){
    let durationVideo = data.duration
}
...
<Video
   ref={ref => this._video = ref}
   source={{ uri: this.state.video }}
   resizeMode={'cover'}
   repeat={true}
   paused = {true}
   onLoad={() => this._onLoad()}
/>`

I hope this can help you.

josecastillo86
  • 330
  • 1
  • 8