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/