-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter : FirebaseMessaging "onBackgroundMessage" with FFmpegKit #209
Comments
Can you provide more details about which And, does calling another method like |
Tried with following methods, most of them which generate a future session
Yes FFmpegKitConfig.getFFmpegVersion() works. with or without FCM background and prints the following Put together a sample app for this use case with 3 branches https://github.com/ujwalparker/audio-mixer/tree/ffmpeg-kit/issues-209-audio-mixer
https://github.com/ujwalparker/audio-mixer/tree/ffmpeg-kit/issues-209-fcm-added
Only thing not executed is below lines of code
You can have a look at the change sheet for the above 3 branches with changes made. (issues-209-fcm-added and issues-209-fcm-background-disabled) |
I suggest asking this behaviour to Firebase devs. There are similar errors reported for other plugins when they are registered through |
@tanersener I do not think this has any interference with Firebase. I spent some time to understand if there is any conflict in the method channel naming etc. but could not find any. I left the onBackgroundMessage handler active and tried to invoke FFprobeKit.getMediaInformationAsync using the "ffmpeg_kit_flutter_min" package this time (does not have relevance to changing the package - I was just trying to reduce the APK size - unrelated)
Why I say its unrelated - because the onListen() is called on the FFmpegKitFlutterPlugin and the log clearly prints the eventSink id. which mean that the successAsync was invoked by asyncMediaInformationSessionExecute and AsyncWriteToPipeTask also invoked. I could only see one FFmpegKitFlutterPlugin instance created - and that was after the call was made to FFprobeKit.getMediaInformationAsync on a user interaction of a button. Attached logs, 1st is after launch of app where Firebase plugin is initialized. 2nd on invoking getMediaInformationAsync 1. FlutterFirebaseMessagingBackgroundService.txt Thoughts? |
Why don't you use the version we have on issue-209 branch, it has more detailed logs? |
Ok will use that and report back. |
@tanersener @ujwalparker I got this error too when using FFmpeg with Firebase Messaging 'background handler'. Hope to see a solution for this. |
@tanersener those logs helped. And yes your initial comment about two instances of FFmpegKitFlutterPlugin objects created is right - but this is expected behavior IMO (but why? more on that towards the end) Firebase Messaging background service triggers the second object creation and that is where the bug manifests. The issue is in the way eventSink is used across and since it is reinitialized when the new FFmpegKitFlutterPlugin object gets created, When the FFmpegKitConfig methods are called they are sending the result back on a eventSink which is now null. I have thought of a crude low impact fix which solves the issue by way of using a static eventSink - to see if this fixes the issue and it does fix - this is crude because this uses a singleton initializer just to use a static eventSink. Checkout the commit @ https://github.com/ujwalparker/ffmpeg-kit/commit/8cc4bd0608551b44142aa25d7173cb7fa7b40fe0 This is not a fix Firebase will accept or review IMO - although I find it weird on why implementation of the background callback triggers an initialization :P. Found an issue which was closed for lack of support on their repo. I have not raised this as a PR as I would not call this as an efficient fix as I do not fully understand the architecture of this plugin. It might possibly be an easier fix from your POV. Let me know if with this you can see a possible solution which is not as crude as the commit. Here is a gist with the above fix working with _firebaseMessagingBackgroundHandler enabled cc. @ifananomali |
I made a minor change in the issue-209 branch which might help you in your case. Try that please. It's the best I can do at the moment. |
@tanersener the change on that branch also works !!. You can take this into the main branch as it will solve this issue for all who want to use this plugin and have FCM integrated (which should be like 90% developers :P) |
I'm also using FCM, and had the same error message. Using the branch:
the error message is fixed, but I'm getting
Log:
Note that from the logs it looks like the @ujwalparker Did you check the return code? |
Yeah the callback did return success. I did not use the function you have used. Have you checked if the command works and does not have any issue? |
I updated the Remember that the change we made fixes only the cases where @yanivshaked returnCode can be null. See the documentation we added for the getReturnCode method. |
Thanks. Indeed it can be null, but in my case it means that the operation did not proceed/perform as planned. If this is the first call to the ffmpeg-kit, either the session has not started or failed. |
@yanivshaked Those three lines show that two statistics entries were produced and a session was completed natively. And those 3 events were forwarded through the event channel. But we can't see whether execution was successful or not in the logs. You have the |
@tanersener I have added the following inquires to the
And got the following:
But when adding a short delay of 2 seconds (
This show that the |
If you look at FFmpegKitFlutterPlugin.java:
|
@yanivshaked I think there is a misunderstanding about If you want be notified about the completion then you can provide an |
Ok, that makes sense, in light of the code. Thank you for clarifying.
seems to be working. |
I am also facing the same issue while working with FirebaseMessaging. Is there any way to solve this issue? |
Are there any workarounds available other than using the dev branch and building the package manually (we are using LTS)? If not, what is the the ETA for the fix to be released? Thank you |
We are publishing the dates for the releases under the Projects page. It is January 2022 for the next one. |
Where to add this function?? |
If anyone cannot wait till January (we cannot), I forked the repo to expose the pre built packages (no other changes were made). You can reference it in ffmpeg_kit_flutter:
git:
url: https://github.com/shilangyu/ffmpeg-kit
ref: development-flutter
path: prebuilt/bundle-flutter-lts/default and replacing |
I'm also wondering. Would you mind elaborating so we can learn how to "wait" for the execution to finish? |
Why you taking like this i asked because i don't know 😕 |
I was hoping @yanivshaked could help us learn by explaining how exactly he did it! |
Sorry for my late answer. Since the
I hope this helps, let me know if you need more clarifications. |
Hi @yanivshaked , In the meantime, I have solved in in a far less elegant way, which also works and maybe it's interesting for someone because it's quite simple and low-key, so it might also be helpful for some people: I use a variable and a do-while-loop to check if the execution has finished yet:
|
Two comments:
So your code doesn't recognize the completion event correctly, and will stop when
It is not bullet proof against situations in which the
This method wraps the operation of |
@yanivshaked I think I'll implement the Anyway, I haven't tested your updated
Let me know if there are cases where |
This issue is fixed in the
|
Description
In an app (Flutter) where we have configured FirebaseMessaging (https://pub.dev/packages/firebase_messaging/) with the onBackgroundMessage handler the FFmpegKit plugin is not usable as there seems to be some conflict due to which the EventChannel which is created by this plugin is rendered null
Expected behavior
Methods like FFmpegKit.executeAsync or FFprobeKit.getMediaInformationAsync or others execute with a result.
Current behavior
The methods FFmpegKit.executeAsync or FFprobeKit.getMediaInformationAsync or others fail with the following sample error
W/ffmpeg-kit-flutter(32468): ResultHandler can not send event {FFmpegKitExecuteCallbackEvent={createTime=1635353254392, startTime=1635353254414, sessionId=1, type=1, command= -i /data/user/0/com.arre.voice/app_flutter/effects/drumroll.wav -i /data/user/0/com.arre.voice/app_flutter/effects/cheer.wav -i /data/user/0/com.arre.voice/app_flutter/effects/boo.wav -filter_complex amix=inputs=3:duration=longest -y /storage/emulated/0/Android/data/com.arre.voice/files/[#6d178].m4a}} on a null event sink.
To Reproduce
Just add FirebaseMessaging to the app and implement onBackgroundMessage handler.
Screenshots
Logs
successAsync gets called for any method but eventSink is render null thus the error message printed by the plugin
Log.w(LIBRARY_NAME, String.format("ResultHandler can not send event %s on a null event sink.", object));
Environment
Other
FirebaseMessaging has 3 handlers as below ( firebase_messaging: ^10.0.7)
When you just do not set the "FirebaseMessaging.onBackgroundMessage" handler the plugin works fine.
The text was updated successfully, but these errors were encountered: