Closed nhimrmh closed 1 year ago
I also facing this issues. Is there any workaround?
Yes, even I am facing this issue, I'm using this package to play the ringtone whenever I receive a firebase push notification even when the app is in the background, and when the app is resumed I'm calling FlutterRingtonePlayer.stop() which is not stopping the ringtone from playing.
@LaxmikanthMadhyastha sir, have you found solutiontion for this ? if yes then can you please share solution ? i also want to play ringtone when app is in background..thank you
Unfortunately, i haven't found any solutions around for this. I think we can only wait for FlutterRingtonePlayer package to be updated as they fix this.
@nhimrmh sir, i am using FlutterRingtonePlayer.playRingtone() in BackgroundMessageHandler of notification whenever i receive notificaiton then ringtone generate MissingPluginException.
Unhandled Exception: MissingPluginException(No implementation found for method play on channel flutter_ringtone_player) have you idea about this error..can you please guide me ?
@Bharavi26 sorry but I can't help you with this because I stopped using this package for a long time since there's no other ways to work around the bug of not capable to stop the ringtone in background, and I haven't been through your kind of exception yet.
in your flutter_project/android/app/src/main/your.package.name/Application.java | MainActivity.java add this import :
import io.inway.ringtone.player.FlutterRingtonePlayerPlugin;
then add this line in the overrided registerWith function:
FlutterRingtonePlayerPlugin.registerWith(registry.registrarFor("io.inway.ringtone.player.FlutterRingtonePlayerPlugin"));
your problem should be solved
Hey @Bharavi26, @nhimrmh I used port communication between the isolates:
fcmBackgroundHandler() async {
...
ReceivePort receiver = ReceivePort();
IsolateNameServer.registerPortWithName(receiver.sendPort, portName);
receiver.listen((message) async {
if (message == "stop") {
await FlutterRingtonePlayer.stop()
}
});
}
And then whenever I want to stop it:
IsolateNameServer.lookupPortByName(portName)?.send("stop");
@Bharavi26 regarding the exception are you sure flutter is intialized correctly and your backgroundhandler is a top-level function?
@liquidiert thank you so much that worked like a charm :)
For anyone who would stumble upon this issue, Here's the complete code sample. Where I am trying to stop the audio on tapping notification (The audio was played while the app was terminated).
This issue has stalled.
This issue has been closed due to inactivity.
Any update regarding this issue?
Hello,
I was facing the same issue with the ringtone not stopping when expected. After some debugging, I found that the issue was with the way the ringtone
instance was being managed in the FlutterRingtonePlayerPlugin
class. Here's the root cause and the solution:
Root Cause:
When the play
method is called, the plugin checks if a ringtone
instance exists. If it does, it stops that instance and creates a new ringtone
instance. However, when the stop
method is called, the plugin stops the ringtone
instance, but it does not nullify it. As a result, there is no persistent reference to the ringtone that's currently playing. So, when FlutterRingtonePlayer.stop()
is called from the Flutter code, the plugin tries to stop the current ringtone
. But if ringtone
is null
, nothing is stopped, and the ringtone continues to play.
Solution:
To fix this, I made the ringtone
instance static so it's shared across all instances of FlutterRingtonePlayerPlugin
. I also added code to nullify the ringtone
instance after stopping it in the stop
method. This ensures that the correct ringtone
is stopped when FlutterRingtonePlayer.stop()
is called from the Flutter code.
Here's a link to my forked repository with the fix: Forked Repository
You can use this repository in your Flutter application by replacing the flutter_ringtone_player
dependency in your pubspec.yaml
file as follows:
dependencies:
flutter:
sdk: flutter
flutter_ringtone_player:
git:
url: https://github.com/KawindaWAD/flutter_ringtone_player.git
@maheshmnj It appears that you have an active Firebase secret included in code sample from your comment, please revoke it....
@maheshmnj It appears that you have an active Firebase secret included in code sample from your comment, please revoke it....
Thanks @SPodjasek, However that secret was for a sample project and I removed it.
I'm currently using flutter_ringtone_player package to implement an Alarm application on mobile. I have AlarmManager to help schedule the time to fire FlutterRingtonePlayer.play() when time comes. If i play and stop the alarm without closing my app then everything works fine, but after closing (killing) my app, the command FlutterRingtonePlayer.stop() on the previous scheduled alarm no longer works when the app is reopened. How can i resolve this? Thank you.