如何使用此异步函数的回调参数来了解我的函数何时完成执行?
一般来说,颤振和异步编程是新手。我想使用这个函数:
https://pub.dev/documentation /ffmpeg_kit_flutter/latest/ffmpeg_kit/FFmpegKit/executeAsync.html
我不明白这部分内容
如果您想收到结果通知,则必须使用 FFmpegSessionCompleteCallback。
有人可以解释一下如何使用它,就像我是初学者程序员一样吗?我可以使用此参数向控制台打印一条简单的消息,例如“执行完成”吗?
到目前为止我尝试过的:
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'不能分配给参数类型“void Function(FFmpegSession)?”。
New to flutter and async programming in general. I want to use this function:
https://pub.dev/documentation/ffmpeg_kit_flutter/latest/ffmpeg_kit/FFmpegKit/executeAsync.html
I don't understand the part that says
You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
Can someone explain how to use this as if I was a beginner programmer? Is this parameter something I can use to print a simple message to the console, like 'execution finished'?
What I've tried so far:
String test1() {
return 'FFMPEG FINISHED';
}
...later in the code
await FFmpegKit.executeAsync('ffmpeg -i ' + FileDir.path + currentFilename + ' ' + FileDir.path + currentOutputFilename + '.mp3', test1());
This gives an error pointing to the end of the await FFmpegKit...
line: The argument type 'String' can't be assigned to the parameter type 'void Function(FFmpegSession)?'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作完成时将调用回调。但是,当您这样做时,
您并没有传递回调。相反,您自己调用您的函数并传递结果(由于类型错误而失败)。
您需要传递函数本身,而不是调用它的结果:
此外,您的
test1
回调具有错误的签名,并且它不会执行任何操作,因为它只返回一个不会使用的值任何地方。因此,您需要进行额外的更改:The callback will be invoked when the operation completes. However, when you do
you're not passing a callback. Instead, you're invoking your function yourself and passing the result (which fails with a type error).
You need to pass the function itself, not the result of invoking it:
Additionally, your
test1
callback has the wrong signature, and it will not do anything since it just returns a value that won't be used anywhere. You therefore need to make an additional change: