I was wondering if there is a method to play an audio file on receiving a push notification. It's a short tone of 1second which I want to play for about 1minute at a gap of 10seconds each. Thus, playing the file 6 times in a minute.
This audio file is locally stored in the APP itself.
So, is there a way in which this can be done without running background services and when the app is closed?
Related
I am working on an Ionic app, that connects with websocket server and when the app receives new message I want to play audio in a loop till user reacts to it.
All of that works when the app is open. When the app is in the background (or the phone is locked), the sound is not played (either this or the message is not received at all).
Basically, I want similar behaviour to the Meta's Messanger app.
How can I achieve that? I guess I lack some basic mobile app development knowledge, because I do backend on daily basis.
I am developing it for Android.
I am able to play Remote Push Notification sound. But sound stops as soon as the sound file placed in raw folder plays completely.
I want to play sound in repeat mode till there is a user action.
Can't use FLAG_INSISTENT with notification builder as it is a remote notification.
In my app, the user have an option to record video. While the user is recording video, if the app triggers a local notification, the notification sound is missing.
But apps like Hangouts, System alarm etc. are able to trigger a notification with sound.
Tried setting notification priority to maximum, requesting audio focus but no luck.
notificationBuilder.setPriority(2);
notificationBuilder.setSound(soundUri, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
Is there a way to trigger a notification with sound, when camera recording is on ? Or is this the default behaviour ? Workarounds ?
Environment: Nexus 7, Android 6.0.1
PS: Whatsapp is able to generate notifications with sound on One Plus 2(Android 6.0.1) when video recording is on.
I am trying to play Notification Sound without disturbing other Music playing
Notification Sound can be played by 2 ways
1) Played by OS itself via NotificationBuilder
Benifits:- Handle itself all the cases of not playing sound in Phone Calls and other cases as well
Problem:- When music is playing and notification comes, then it shifts audio focus from music to notification, there by lowering or silencing music depending on how that music player app has handled the loss in audio focus.
2) We play sound via our media Player whenever notification comes
A) Play on NOTIFICATION STREAM ---> works perfectly fine but gives probem of ducking when played via earphones
B) Play on SYSTEM STREAM
Benifits:- No shifting of audio focus, so no effect on music when notification comes
Problem:- We will have to handle other cases of not playing sound in Telephonic call and VOIP as well...and may be other not known cases as of now .
But I figured it that watsup is doing fine.
So don't know how it is doing it
Per the Android 5.0 behavior changes on notification sounds:
If you are currently adding sounds and vibrations to your notifications by using the Ringtone, MediaPlayer, or Vibrator classes, remove this code so that the system can present notifications correctly in priority mode. Instead, use Notification.Builder methods to add sounds and vibration.
Setting the device to RINGER_MODE_SILENT causes the device to enter the new priority mode. The device leaves priority mode if you set it to RINGER_MODE_NORMAL or RINGER_MODE_VIBRATE.
Previously, Android used STREAM_MUSIC as the master stream to control volume on tablet devices. In Android 5.0, the master volume stream for both phone and tablet devices is now unified, and is controlled by STREAM_RING or STREAM_NOTIFICATION.
As there is not a direct way to detect whether a device is in priority mode, you should always use the Notification.Builder/NotificationCompat.Builder methods to add sound to your notifications to ensure you meet the user's expectations.
I want to play one Audio file continuously that is being downloaded. Please note that there is no file of fixed size being sent from other side. It's like data is being send from one side and on the other side data is being received. I just want to make this data keep on playing (audio) until no further data is available.
Any suggestions on how to play audio data that is being sent continuously as soon as you start receiving it?