android - 如何使用此异步函数的回调参数来知道我的函数何时完成执行?

标签 android ios flutter dart ffmpeg

Flutter 和异步编程的新手。我想使用这个功能:
https://pub.dev/documentation/ffmpeg_kit_flutter/latest/ffmpeg_kit/FFmpegKit/executeAsync.html
我不明白说的部分

You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.


有人可以像我是初学者一样解释如何使用它吗?这个参数是我可以用来向控制台打印一条简单消息的东西吗,比如“执行完成”?
到目前为止我尝试过的 :
String test1() {
    return 'FFMPEG FINISHED';
  }

...later in the code

await FFmpegKit.executeAsync('ffmpeg -i ' + FileDir.path + currentFilename + ' ' + FileDir.path + currentOutputFilename + '.mp3', test1());
这给出了指向 await FFmpegKit... 结尾的错误。线路:The argument type 'String' can't be assigned to the parameter type 'void Function(FFmpegSession)?'.

最佳答案

操作完成时将调用回调。但是,当你这样做

await FFmpegKit.executeAsync(..., test1());
你没有通过回调。相反,您自己调用函数并传递结果(由于类型错误而失败)。
您需要传递函数本身,而不是调用它的结果:
await FFmpegKit.executeAsync(..., test1);
此外,您的 test1回调有错误的签名,它不会做任何事情,因为它只是返回一个不会在任何地方使用的值。因此,您需要进行额外的更改:
void test1(FFmpegSession session) {
  print('FFMPEG FINISHED');
}

关于android - 如何使用此异步函数的回调参数来知道我的函数何时完成执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71280375/

相关文章:

android - 选项卡下的最大选项卡数和线条颜色?

android - 为 Android Studio 安装支持库

ios - 如何在不关心大小的情况下制作斜体 UILabel?

ios - 检查给定字符是否是 Objective-C 中的表情符号

android - 如何在 Android 上使用 Flutter 成功完成应用内购买?

java - Android:按钮不起作用

c# - 在monodroid webview中加载带有pdf的url

ios - 为什么这本字典中的值会改变?

Flutter setState重建整页效果

android - Flutter 是否提供即时应用程序?