Reputation: 402
I want to create a simple (hoping simple) app in which a user selects a person, pushes a button, and a custom sound plays on the selected persons phone (given they have the same app installed). Kind of like a manual notification for if you planned to meet someone at a place or event you could push your button and a sound would play to let them know you've arrived. I'm doing this to try and learn mobile and programming in general.
I don't need the update (sound) to be instant so would I do something like push notifications or long polling? Whats best practice or easiest to implement with flutter so that if the app is in the background it can act on notifications or poll data it receives (play the sound)? How do I trigger the sound to play off a notification? Is firebase a google place to use for this type of notification system?
There is only one sound I want to play (no ones recording their own or anything) so I'm assuming I can include the sound file locally which should be easy to play? I don't see audio or sound in the flutter documentation so is a plugin my easiest option?
I'm new to mobile and flutter in general so please forgive me if my terminology or ideas are a bit off.
Upvotes: 0
Views: 1275
Reputation: 1312
There is no way to catch the notification(firebase cloud message) when your app in the background, and system will show the notification in system tray and play the default sound.
If you want to customize notification sound while your app is in background, you can change it by adding 'sound' parameter in notification payload, the system will play for you while your app is in the background. Please check it. https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
Ex,
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon",
"sound" : "mySound" <---right here.
}
Upvotes: 0
Reputation: 276957
You can use AudioPlayer
which is an external plugin
I linked the fork of the original >>AudioPlayer
<< because that fork is more advanced then the original.
Upvotes: 1