问题描述
我无法让我选择的视频或录制的视频生成路径并上传到 Firebase。它一直说路径不应该为空。我不确定我哪里出错了。我还试图弄清楚如何在将视频上传到 Firebase 之前对其进行压缩,这样它们就不会占用太多空间。有没有人可以帮我解决这个问题?
这是我得到的错误:Unhandled Exception: Invalid argument(s) (path): Must not be null
这是我目前所拥有的:
这是我拍摄视频或照片的地方(顺便说一句,照片可以在拍照后添加过滤器)
void _onImageButtonpressed(ImageSource source) async {
if (_controller != null) {
_controller.setVolume(0.0);
_controller.removeListener(_onVideoControllerUpdate);
}
if (isVideo) {
ImagePicker.pickVideo(source: source,maxDuration: Duration(seconds: 10))
.then((File file) {
if (file != null && mounted) {
setState(() {
_controller = VideoPlayerController.file(file)
..initialize()
..addListener(_onVideoControllerUpdate)
..setVolume(1.0)
..setLooping(true)
..play();
});
}
});
setState(() {
this.file = videoFile;
});
fileName = basename(videoFile.path);
//var image = ImD.decodeImage(imageFile.readAsBytesSync());
} else {
try {
imageFile = await ImagePicker.pickImage(source: source);
if (imageFile != null) {
imageFile = await cropImage(imageFile);
setState(() {
this.file = imageFile;
});
fileName = basename(imageFile.path);
var image = ImD.decodeImage(imageFile.readAsBytesSync());
//image = ImD.copyResize(image,height: 400);
Map imagefile = await Navigator.push(
this.context,new MaterialPageRoute(
builder: (context) => new PhotoFilterSelector(
appBarColor: Colors.white,title: Text(
"Pick A Filter",style: TextStyle(color: R.colors.primaryColor),),image: image,filters: presetFiltersList,filename: fileName,loader: Center(child: CircularProgressIndicator()),fit: BoxFit.contain,);
if (imagefile != null && imagefile.containsKey('image_filtered')) {
setState(() {
this.file = imagefile['image_filtered'];
});
}
}
} catch (e) {
_pickImageError = e;
}
setState(() {});
}
}
这是我想要压缩视频的地方。但它不起作用
compressingVideo() async {
//final tDirectory = await getTemporaryDirectory();
//final path = tDirectory.path;
await VideoCompress.setLogLevel(0);
final compressedVideoFile = await VideoCompress.compressVideo(
videoFile.path,quality: VideoQuality.MediumQuality,deleteOrigin: false,includeAudio: true,);
setState(() {});
}
这是我的上传和保存功能,它没有为视频获取正确的路径。错误指向 UploadVideo 行
controlUploadAndSave() async {
setState(() {
uploading = true;
});
if (!isVideo) {
//Uploading a Photo
await compressingPhoto();
String downloadUrl = await uploadPhoto(file);
savePostInfoToFireStore(
url: downloadUrl,location: locationTextEditingController.text,description: descriptionTextEditingController.text);
locationTextEditingController.clear();
descriptionTextEditingController.clear();
setState(() {
file = null;
uploading = false;
postId = Uuid().v4();
});
Fluttertoast.showToast(msg: R.strings.updatedSuccessfully);
}
//Uploading a Video
else {
//await compressingVideo();
String downloadVideoUrl = await uploadVideo(fileName);
savePostInfoToFireStore(
url: downloadVideoUrl,description: descriptionTextEditingController.text);
locationTextEditingController.clear();
descriptionTextEditingController.clear();
setState(() {
videoFile = null;
uploading = false;
postId = Uuid().v4();
});
Fluttertoast.showToast(msg: R.strings.updatedSuccessfully);
}
}
这是不工作的uploadVideo 功能。另一个错误指向 .putFile 行
Future uploadVideo(mVideoFile) async {
//StorageReference ref = videoReference.child("video_$postId");
StorageUploadTask videoUploadTask = videoReference
.child("video_$postId.mp4")
.putFile(File(mVideoFile),StorageMetadata(contentType: 'video/mp4'));
StorageTaskSnapshot storageTaskSnapshot = await videoUploadTask.onComplete;
var downloadVideoUrl = await storageTaskSnapshot.ref.getDownloadURL();
final String url = downloadVideoUrl.toString();
return url;
}
对此的任何帮助将不胜感激。我这辈子都搞不清楚。此外,任何有关压缩视频功能的提示都会有很大帮助!但是我确定我是否至少可以在选择视频后生成一条路径,这可能会帮助我进行压缩(希望如此)。无论如何,如果我遗漏了任何有价值的信息,请告诉我。我试图包括所有涉及视频问题的内容,而不用不相关的部分使代码混乱。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)