fluttermediainfovideo-compression

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(); returns a type of Future<MediaInfo>

Syntax Error is as follows 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.

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


Solution

  • that's because compressVideo function doesn't return MediaInfo, it returns Future so you need to await for it.

    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);
    });