flutter_ringtone_player
flutter_ringtone_player copied to clipboard
Using android service to start and stop ringtones
In two scenarios you are not able to stop alarm ringtones again with the current implementation:
- If a app gets called back by the official android_alarm_manager
- If a app is reopened after it was killed, see #7
In the first case, when you call FlutterRingtonePlayer#playAlarm from the callback a second instance of FlutterRingtonePlayerPlugin is running. Because the reference to ringtone is different (null) from the first (start) call the stop call won't work. I'm not sure why there are two instances running but I guess it relates to the fact that the callback will not run in the same isolate as the main app.
In the second case the reference just gets lost.
Anyway, in both cases the reason is that FlutterRingtonePlayerPlugin holds the ringtone reference in a transient way.
This is why I moved the start/stop code to a separate android service.
I just checked out: https://stackoverflow.com/questions/42126979/cannot-keep-android-service-alive-after-app-is-closed https://developer.android.com/guide/components/services#Foreground
The service in this pull request is a background service. Maybe it's not enough to fix the second case... I will stay tuned.
Alarm sounds remain playing even if you close and reopen the app. You have to stop it explicitly by the given stop method.
Have you tested this? Should I still use this Pull?
This won't work if the asAlarm parameter set to true for the playNotification method case, please update that too.
@aybefox Can you rebase your changes to current HEAD?
Any update on this?
This pull request has stalled.