本文主要是介绍【flutter video_thumbnail库获取缩略图】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/** 获取视频缩略图* video_thumbnail库: 如果所选视频已生成过缩略图,那就再次生成时会报错* */getVideoThumbnail(String videoPath,{int maxWidth,int maxHeight,int quality}) async {Completer<String> _completer = Completer<String>();String _thumbPath; //要上传的缩略图本地路径String _photoPath = videoPath.substring(0, videoPath.length - 3) + "jpg"; //将地址后面的mp4去掉,再添加jpg(和imageFormat保持一致),判断这个图片文件是否存在File _photoPathFile = File(_photoPath);var _photoExists = await _photoPathFile.exists();if(_photoExists == true){_thumbPath = _photoPath;}else{_thumbPath = await VideoThumbnail.thumbnailFile(video: videoPath,imageFormat: ImageFormat.JPEG,maxWidth: maxWidth ?? 0,maxHeight: maxHeight ?? 64,quality: quality ?? 25);}_completer.complete(_thumbPath);return _completer.future;}
引用
//图片选择器可以用wechat_assets_picker库// 获取视频缩略图并上传Future <bool> getVideoThumbnail(String videoPath) async {Completer<bool> _completer = Completer<bool>();print('视频文件地址:$videoPath');String thumbnailPath = await Utils().getVideoThumbnail(videoPath);print('thumbnailPath= ${thumbnailPath}');if(thumbnailPath.isEmpty){_completer.complete(false);}else{//上传图片List<String> _fileUrlResult = await UploadOss.uploadByPathList(fileList: [thumbnailPath]);if(_fileUrlResult.isEmpty){_completer.complete(false);}else{state.createExpParams.videoFileUrlPOJODetail.showUrl = _fileUrlResult[0];print('视频封面地址:${state.createExpParams.videoFileUrlPOJODetail.showUrl}');_completer.complete(true);}}return _completer.future;}
这篇关于【flutter video_thumbnail库获取缩略图】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!