当前位置: 首页 > news >正文

如何创建一个网站的步骤专业沈阳网站制作

如何创建一个网站的步骤,专业沈阳网站制作,做网站虚拟主机,网站建设如何选择服务器flutter开发实战-实现获取视频的缩略图封面video_thumbnail 在很多时候#xff0c;我们查看视频的时候#xff0c;视频没有播放时候#xff0c;会显示一张封面#xff0c;可能封面没有配置图片#xff0c;这时候就需要通过获取视频的缩略图来显示封面了。这里使用了video…flutter开发实战-实现获取视频的缩略图封面video_thumbnail 在很多时候我们查看视频的时候视频没有播放时候会显示一张封面可能封面没有配置图片这时候就需要通过获取视频的缩略图来显示封面了。这里使用了video_thumbnail来实现获取视频的缩略图。 一、引入video_thumbnail 在工程的pubspec.yaml中引入插件 # 视频缩略图video_thumbnail: ^0.5.3 VideoThumbnail的属性如下 static FutureString? thumbnailFile({required String video,MapString, String? headers,String? thumbnailPath,ImageFormat imageFormat ImageFormat.PNG,int maxHeight 0,int maxWidth 0,int timeMs 0,int quality 10}) thumbnailPath为本地存储的文件目录imageFormat格式 jpgpng等video视频地址timeMs 二、获取视频的缩略图 使用video_thumbnail来获取视频缩略图 定义视频缩略图信息 class VideoThumbInfo {String url; // 原视频地址File? thumbFile; // 缩略图本地fileint? width; // 缩略图的widthint? height; // 缩略图的heightVideoThumbInfo({required this.url,}); } 获取视频缩略图本地File String path (await getTemporaryDirectory()).path;String thumbnailPath path /${DateTime.now().millisecond}.jpg;final fileName await VideoThumbnail.thumbnailFile(video:https://vd2.bdstatic.com/mda-maif0tt1rirqp27q/540p/h264_cae/1611052585/mda-maif0tt1rirqp27q.mp4,thumbnailPath: thumbnailPath,imageFormat: imageFormat,quality: quality,maxWidth: maxWidth,maxHeight: maxHeight,timeMs: timeMs,);File file File(thumbnailPath); 获取缩略图的宽高 Image image Image.file(thumbFile!);image.image.resolve(const ImageConfiguration()).addListener(ImageStreamListener((ImageInfo imageInfo, bool synchronousCall) {int imageWidth imageInfo.image.width;int imageHeight imageInfo.image.height;VideoThumbInfo videoThumbInfo VideoThumbInfo(url: url);videoThumbInfo.thumbFile thumbFile;videoThumbInfo.width imageWidth;videoThumbInfo.height imageHeight;VideoThumb.setThumbInfo(url, videoThumbInfo);onVideoThumbInfoListener(videoThumbInfo);},onError: (exception, stackTrace) {print(getVideoThumbInfoByFile imageStreamListener onError exception:${exception.toString()},stackTrace:${stackTrace});onVideoThumbInfoListener(null);},),); 完整代码如下 import dart:io; import package:flutter/material.dart; import package:path_provider/path_provider.dart; import package:video_thumbnail/video_thumbnail.dart;// ignore: non_constant_identifier_names VideoThumbManager get VideoThumb VideoThumbManager.instance;class VideoThumbManager {static VideoThumbManager get instance {return _singleton;}//保存单例static VideoThumbManager _singleton VideoThumbManager._internal();//工厂构造函数factory VideoThumbManager() _singleton;//私有构造函数VideoThumbManager._internal();// 保存url对应的本地缩略图filefinal _thumbMap MapString, File();// url对应本地缩略图的信息final _thumbInfoMap MapString, VideoThumbInfo();Futurevoid setThumb(String url, File file) async {if (url.isEmpty) {return;}bool exist await file.exists();if (exist false) {return;}_thumbMap[url] file;}FutureFile? getThumb(String url, {ImageFormat imageFormat ImageFormat.JPEG,int maxHeight 0,int maxWidth 0,int timeMs 0,int quality 100,}) async {File? thumbFile _thumbMap[url];if (thumbFile ! null) {return thumbFile;}String path (await getTemporaryDirectory()).path;String thumbnailPath path /${DateTime.now().millisecond}.jpg;final fileName await VideoThumbnail.thumbnailFile(video:https://vd2.bdstatic.com/mda-maif0tt1rirqp27q/540p/h264_cae/1611052585/mda-maif0tt1rirqp27q.mp4,thumbnailPath: thumbnailPath,imageFormat: imageFormat,quality: quality,maxWidth: maxWidth,maxHeight: maxHeight,timeMs: timeMs,);File file File(thumbnailPath);setThumb(url, file);return file;}// 获取缩略图的大小void getVideoThumbInfo(String url, {ImageFormat imageFormat ImageFormat.JPEG,int maxHeight 0,int maxWidth 0,int timeMs 0,int quality 100,required Function(VideoThumbInfo?) onVideoThumbInfoListener,}) async {try {VideoThumbInfo? thumbInfo VideoThumb.getThumbInfo(url);if (thumbInfo ! null) {onVideoThumbInfoListener(thumbInfo);return;}await VideoThumb.getThumb(url,imageFormat: imageFormat,maxWidth: maxWidth,maxHeight: maxHeight,timeMs: timeMs,quality: quality,).then((value) {File? thumbFile value;if (thumbFile ! null) {VideoThumb.getVideoThumbInfoByFile(url: url,thumbFile: thumbFile,onVideoThumbInfoListener: onVideoThumbInfoListener,);} else {onVideoThumbInfoListener(null);}}).onError((error, stackTrace) {print(getVideoThumbInfo error:${error.toString()});onVideoThumbInfoListener(null);}).whenComplete(() {print(getVideoThumbInfo whenComplete);});} catch (e) {print(getVideoThumbInfo catch error:${e.toString()});onVideoThumbInfoListener(null);}}/// 根据file获取缩略图信息void getVideoThumbInfoByFile({required String url,required File thumbFile,required Function(VideoThumbInfo?) onVideoThumbInfoListener,}) async {try {VideoThumbInfo? thumbInfo VideoThumb.getThumbInfo(url);if (thumbInfo ! null) {onVideoThumbInfoListener(thumbInfo);return;}Image image Image.file(thumbFile!);image.image.resolve(const ImageConfiguration()).addListener(ImageStreamListener((ImageInfo imageInfo, bool synchronousCall) {int imageWidth imageInfo.image.width;int imageHeight imageInfo.image.height;VideoThumbInfo videoThumbInfo VideoThumbInfo(url: url);videoThumbInfo.thumbFile thumbFile;videoThumbInfo.width imageWidth;videoThumbInfo.height imageHeight;VideoThumb.setThumbInfo(url, videoThumbInfo);onVideoThumbInfoListener(videoThumbInfo);},onError: (exception, stackTrace) {print(getVideoThumbInfoByFile imageStreamListener onError exception:${exception.toString()},stackTrace:${stackTrace});onVideoThumbInfoListener(null);},),);} catch (e) {print(getVideoThumbInfoByFile catch error:${e.toString()});onVideoThumbInfoListener(null);}}void removeThumb(String url) {if (url.isEmpty) {return;}_thumbMap.remove(url);}/// 获取存储缩略图信息VideoThumbInfo? getThumbInfo(String url) {if (url.isEmpty) {return null;}VideoThumbInfo? thumbInfo _thumbInfoMap[url];return thumbInfo;}/// 存储缩略图信息void setThumbInfo(String url, VideoThumbInfo videoThumbInfo) async {if (url.isEmpty) {return;}_thumbInfoMap[url] videoThumbInfo;}void removeThumbInfo(String url) {if (url.isEmpty) {return;}_thumbInfoMap.remove(url);}void clear() {_thumbMap.clear();_thumbInfoMap.clear();} }class VideoThumbInfo {String url; // 原视频地址File? thumbFile; // 缩略图本地fileint? width; // 缩略图的widthint? height; // 缩略图的heightVideoThumbInfo({required this.url,}); } 三、显示视频缩略图的Widget 用于显示视频缩略图的Widget /// 用于显示视频缩略图的Widget class VideoThumbImage extends StatefulWidget {const VideoThumbImage({super.key, required this.url, this.maxWidth, this.maxHeight});final String url;final double? maxWidth;final double? maxHeight;overrideStateVideoThumbImage createState() _VideoThumbImageState(); }class _VideoThumbImageState extends StateVideoThumbImage {VideoThumbInfo? _videoThumbInfo;overridevoid initState() {// TODO: implement initStatesuper.initState();VideoThumb.getVideoThumbInfo(widget.url,onVideoThumbInfoListener: (VideoThumbInfo? thumbInfo) {if (mounted) {setState(() {_videoThumbInfo thumbInfo;});}});}overridevoid dispose() {// TODO: implement disposesuper.dispose();}// 根据VideoThumb来显示图片Widget buildVideoThumb(BuildContext context) {if (_videoThumbInfo ! null _videoThumbInfo!.thumbFile ! null) {double? imageWidth;double? imageHeight;if (_videoThumbInfo!.width ! null _videoThumbInfo!.height ! null) {imageWidth _videoThumbInfo!.width!.toDouble();imageWidth _videoThumbInfo!.height!.toDouble();}return Container(width: imageWidth,height: imageHeight,clipBehavior: Clip.hardEdge,decoration: const BoxDecoration(color: Colors.transparent,),child: Image.file(_videoThumbInfo!.thumbFile!,width: imageWidth,height: imageHeight,),);}return Container();}overrideWidget build(BuildContext context) {return ConstrainedBox(constraints: BoxConstraints(maxWidth: widget.maxWidth ?? double.infinity,maxHeight: widget.maxHeight ?? double.infinity,),child: buildVideoThumb(context),);} } 效果图如下 四、小结 flutter开发实战-实现获取视频的缩略图封面video_thumbnail 学习记录每天不停进步。
http://www.sadfv.cn/news/354048/

相关文章:

  • 网站推广渠道类型深圳住建局官网查询系统
  • 网站中的下拉菜单崂山区建设管理局网站怎么了黑
  • 象山县城乡建设局网站网站首页界面设计
  • 机电工程东莞网站建设技术支持龙岩天宫山要爬多久
  • 优化网站排名如何宁德城乡建设部网站首页
  • 毕业设计成品网站深圳网站建设乐云seo
  • 系统网站怎么做的成都网站建设、
  • 网站建设公司公司商城微网站创建
  • 网站规划的原则有哪些建设银行网站网址是什么
  • 长沙优化网站关键词免费域名映射
  • 人脉做的最好的网站建设银行河南省分行招聘网站
  • 长沙优质营销网站建设设计中跃建设集团网站
  • 乐清门户网站弄几个的网站
  • 网站 建设 汇报美篇app怎么制作
  • 肇庆做网站设计如何推广网站架构
  • 如何做一个收费的网站一般网站建设需要多少钱
  • 创意网站建设策划方案wordpress 数据库解析
  • 彩票网站怎么做上海企业网站制作费用
  • 口碑好的常州网站优化免费咨询法律援助电话号码
  • 阿里巴巴专门做外贸的网站网络技术服务是干什么的
  • 旅游网站开发开题报告平面设计网上接单一个月能赚多少
  • 做不了飞机要看什么网站太原哪里做网站好
  • 微网站如何建立网络广告策划流程有哪些?
  • 百度商桥怎样绑定网站怎么用电脑做网站虚拟空间
  • 网站建设济南云畅网络技术有限公司杭州市建设职业中心网站
  • 驻马店北京网站建设wordpress 页面文章
  • 新网网站模板网站设计工程师是it行业吗
  • 一起装修网官方网站出口电商平台有哪些
  • 重新建设网站wordpress添加电影
  • 网站源码建站专业网站制作公司