Skip to content

Using android service to start and stop ringtones#8

Open
aybefox wants to merge 7 commits into
inway:mainfrom
aybefox:master
Open

Using android service to start and stop ringtones#8
aybefox wants to merge 7 commits into
inway:mainfrom
aybefox:master

Conversation

@aybefox

@aybefox aybefox commented Apr 11, 2020

Copy link
Copy Markdown

In two scenarios you are not able to stop alarm ringtones again with the current implementation:

  1. If a app gets called back by the official android_alarm_manager
  2. If a app is reopened after it was killed, see Can't stop the alarm with FlutterRingtonePlayer.stop() after killing the app. #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.

@aybefox

aybefox commented Apr 11, 2020

Copy link
Copy Markdown
Author

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.

@aybefox

aybefox commented Apr 12, 2020

Copy link
Copy Markdown
Author

Alarm sounds remain playing even if you close and reopen the app. You have to stop it explicitly by the given stop method.

@sanidhyaagrawal

Copy link
Copy Markdown

Have you tested this? Should I still use this Pull?

@Ted-chiptech

Copy link
Copy Markdown

This won't work if the asAlarm parameter set to true for the playNotification method case, please update that too.

@SPodjasek

Copy link
Copy Markdown
Member

@aybefox Can you rebase your changes to current HEAD?

@SPodjasek SPodjasek mentioned this pull request Jan 25, 2022
@SPodjasek SPodjasek linked an issue Jan 25, 2022 that may be closed by this pull request
@SPodjasek SPodjasek added this to the 3.3.0 milestone Apr 7, 2022
@Alvarocda

Copy link
Copy Markdown

Any update on this?

@github-actions

Copy link
Copy Markdown

This pull request has stalled.

@github-actions github-actions Bot added the stale label May 15, 2024
@github-actions github-actions Bot removed the stale label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to stop Ringtone

6 participants