简体   繁体   English

颤动的VideoCompress Mediainfo错误

[英]VideoCompress Mediainfo error with flutter

Hello I am having an issue where when trying to set the type of a variable mediainfo flutter requires that VideoCompress.compressVideo();您好我遇到一个问题,当尝试设置变量 mediainfo 颤振的类型时需要VideoCompress.compressVideo(); returns a type of Future<MediaInfo>返回Future<MediaInfo>的类型

Syntax Error is as follows A value of type 'Future<MediaInfo>' can't be assigned to a variable of type 'MediaInfo'.语法错误如下A value of type 'Future<MediaInfo>' can't be assigned to a variable of type 'MediaInfo'.

And when using VideoCompress.getMediaInfo(file) it seems to not return a MediaInfo type as when I try to assign it to a variable it fails to provide the .path method.当使用VideoCompress.getMediaInfo(file)时,它似乎没有返回 MediaInfo 类型,因为当我尝试将它分配给一个变量时,它无法提供.path方法。

Here is an example of the code.这是代码的示例。

static Future<MediaInfo> compressVideo(file, context) async{
    await VideoCompress.compressVideo(file,
        quality: VideoQuality.HighestQuality, deleteOrigin: true);
    final info = VideoCompress.getMediaInfo(file);

    return info;

Attempt of trying to access .path click me尝试访问.path点击我

that's because compressVideo function doesn't return MediaInfo, it returns Future so you need to await for it.那是因为compressVideo函数不返回MediaInfo,它返回Future,所以你需要等待它。

final info = await VideoCompressApi.compressVideo(filePath, context);
setState((){
  compressedInfo = info.path;
});

Edit: you can also use:编辑:您还可以使用:

VideoCompressApi.compressVideo(filePath, context).then((info) {
  setState(() => compressedInfo = info.path);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM