Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

Throw error when using with plugin firebase_messaging

Open mminhlequang opened this issue 3 years ago • 12 comments

Platform : Android

I use assets_audio_player: ^3.0.3+2 in my project with firebase_messaging: ^9.1.1. That all ok but when open application by click on notification message from firebase this throw:

MissingPluginException(No implementation found for method open on channel assets_audio_player)

mminhlequang avatar Apr 16 '21 04:04 mminhlequang

I am facing the same issue also, anyone has got any sollution ?

samrat19 avatar Apr 24 '21 13:04 samrat19

I had remove this package and use just_audio in my project. assets_audio_player response is too slow :(

mminhlequang avatar Apr 25 '21 01:04 mminhlequang

I had remove this package and use just_audio in my project. assets_audio_player response is too slow :(

Did you manage to get just_audio to do what you want? I want to play a sound repeatedly when receiving a push notification, and stop it when the user opens the app, I can play the file when receiving a push notification, but couldn't stop it as the firebase message onBackgroundMessage is in an isolate mode, did you had any success?

Ted-chiptech avatar Jul 12 '21 04:07 Ted-chiptech

Nope @Ted-chiptech I just got issue when handle onBackgroundMessage with this plugin. i don't know why but i've remove it 👯

mminhlequang avatar Jul 12 '21 08:07 mminhlequang

Replacing this package with some other package shouldn't be a reason of closing this issue. In our Sentry logs we also started to see the same exception.

ulusoyca avatar Aug 26 '21 07:08 ulusoyca

@ulusoyca reopened.

kalismeras61 avatar Aug 26 '21 07:08 kalismeras61

I faced same Issue . could you please advise me . To solve this Problem . Thank You

https://stackoverflow.com/questions/69522573/missingpluginexception-when-using-a-plugins-with-alarm-manager-call-back

sshadkany avatar Oct 12 '21 07:10 sshadkany

I faced same Issue . could you please advise me . To solve this Problem . Thank You

https://stackoverflow.com/questions/69522573/missingpluginexception-when-using-a-plugins-with-alarm-manager-call-back

I use the audio_service package instead, it does the trick.

Ted-chiptech avatar Oct 12 '21 21:10 Ted-chiptech

It seems like I'm facing the same issue: MissingPluginException after the app was started from click on notification :/

Did anyone make any progress there?

komaxx avatar Dec 01 '22 16:12 komaxx

Ok, I have a hunch now:

When we're using push messages, FirebaseMessages spins up a new isolate (think: it's own little Dart app) to handle the incoming message. If the app was not running at that point, it is started, and Firebase's isolate is the first Dart engine to exist. Now, when Flutter starts, it initializes all the plugins, including assets_audio_player. Initialization happens by calling onAttachedToEngine on all plugins (that's done by the auto-generated GeneratedPluginRegistrant.java class). This seems to be done for all Isolates, Firebase's and Flutter's main. Isolates share the same Android process, though.

And here comes the problem: In AssetsAudioPlayerPlugin.kt the first line of onAttachedToEngine reads like this:

if(instance != null)return // bug fix

So, my guess is:

  • a push comes in
  • Firebase spins up a new Isolate
  • In this isolate, plugins are initialized
  • the app comes to foreground, running in its main isolate
  • plugins are initialized again for the main isolate
  • this time, though, assets_audio_player does NOT register its MethodCallHandler as there is already an instance running
  • when we access anything offered by the plugin, it crashes as no MethodCallHandler is registered in Flutter's main isolate.

At least, that's my understanding so far.

@florent37 Does this make sense to you? Can you remember why the if(instance != null)return // bug fix was introduced in the first place?

komaxx avatar Dec 01 '22 17:12 komaxx

Any news?

JosephNK avatar Mar 26 '23 12:03 JosephNK

It got added here - https://github.com/florent37/Flutter-AssetsAudioPlayer/commit/bb106b635a257d107da9dfccf5adaef58ff53cf2

any idea @kalismeras61 ?

vlowe85 avatar Sep 15 '23 10:09 vlowe85