pickVideo static method
Future<File?>
pickVideo(
- BuildContext context, {
- bool isGallery = true,
- bool shouldCompress = false,
Implementation
static Future<File?> pickVideo(BuildContext context,{bool isGallery = true, bool shouldCompress=false})async{
final ImagePicker picker = ImagePicker();
File? video;
// String? videoFile;
try{
XFile? pickedVideo;
if(isGallery){
pickedVideo = await picker.pickVideo(source: ImageSource.gallery,);
}else{
pickedVideo = await picker.pickVideo(source: ImageSource.camera,preferredCameraDevice: CameraDevice.rear,);
showSnackbar(context:context,'video logs 1.1: picked video $pickedVideo',storeLogs: true);
}
/// commented as video compress not working currently
// if(shouldCompress)
// {
// MediaInfo? mediaInfo = await VideoCompress.compressVideo(
// pickedVideo!.path.toString(),
// quality: VideoQuality.LowQuality,
// deleteOrigin: false, // It's false by default
// );
// File fi = File(pickedVideo.path.toString());
// int fileSize = await fi.length();
// print('before compress video $fileSize bytes');
// print('after compress video ${mediaInfo!.filesize}');
// video= File(mediaInfo.path.toString());
// return video;
// }
int videoLength = await pickedVideo!.length();
showSnackbar(context: context,'video logs 1.11: Video length $videoLength, now converting xfile to file',storeLogs: true);
customPrint('the length of the video is');
customPrint(videoLength);
// if(videoLength>10485760){
// if(videoLength>1085760){
// showSnackbar(MyGlobalKeys.navigatorKey.currentContext!, 'Video must be less than 1 mb');
// // return null;
// }
video = File(pickedVideo.path);
showSnackbar(context:context,'video logs 1.12: File converted successfully',storeLogs: true);
// videoFile = pickedVideo.path;
showSnackbar(context:context,'video logs 1.13: path success',storeLogs: true);
}catch(e){
customPrint('Error in picking video $e');
showSnackbar(context:context,'video logs 1.14: Error in picking video $e',storeLogs: true);
}
return video;
}