flutter image picker maxDuration issue

1k views Asked by At

I'm using image picker plugIn from flutter.dev official. And now I'm facing weird issue with setting the maxDuration of choosing video. Following is my code now:

pickVideoFromGallery() async {
Navigator.pop(context);
File videoFile = await ImagePicker.pickVideo(
    source: ImageSource.gallery, maxDuration: const Duration(seconds: 10));
int helloInt = await videoFile.length();
int byebyeInt = videoFile.lengthSync();
print(helloInt);
print(byebyeInt);
setState(() {
  this.fileForThumbnailEXPRMT = videoFile;
});}

with the version of image_picker: ^0.6.0+2

I'm trying to set maxDuration of picked video for 10 seconds, so that user cannnot upload video over length of 10 seconds. Although I'm using deprecated method, I'm sure that maxDuration code must work just fine because all the other parts of imagePicker work just fine on all os and sw versions. But when I set the maxDuration to 10s and test it on the device, there happened nothing. I picked video of 3 minutes and the code didn't limited the process, which actually should not happen in my case. Am I misunderstanding the concept of maxDuration argument, or is my code wrong when setting maxDuration of video?

Does anyone know how to set maxDuration of video perfectly? I tried various ints for setting the maxDuration but it didn't work with all those ints.

Clear answers appreciated! Thank you in advance [:

1

There are 1 answers

3
menote nhanga On BEST ANSWER

I don't think you can do it with ImagePicker because of this plugin capture video by phone default camera app and you haven't access to check and manage duration while capturing until the user stops capturing and return to your application.

My advice would be to use Camera plugin https://pub.dev/packages/camera and use timer to stop recording.