/*
  * 获取视频缩略图
  * 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;
  }

更多推荐