Reputation: 2276
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)?'.
Upvotes: 1
Views: 644
Reputation: 90125
The callback will be invoked when the operation completes. However, when you do
await FFmpegKit.executeAsync(..., test1());
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:
await FFmpegKit.executeAsync(..., test1);
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:
void test1(FFmpegSession session) {
print('FFMPEG FINISHED');
}
Upvotes: 2