Is there a possibiltiy to detect which app is sending sound? I only found a solution to recognize there is sound playing, but not which app is playing it.
Related
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 make a android application for play sound.
I use the service for playing sound, however when close the app service stopped then music stopped.
Please help me
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 detect if the Android Phone speaker is in use by any App like whether Music Player is playing Music or Alarm is Ringing or Video is playing. I dont want to detect just if a specific App is using the Ringer all i want to do is get Notified if the Ringer is used by Any APP.
It's easy to detect when phone calls come in (via phoneStateListener), but what about other notification sounds, such as email or sms?
On some devices, these notification sounds mute but don't pause any currently running mediaPlayer instances, which is annoying for the user. Ideally, I'd like to listen for notifications that play sound, pause playback for the duration, and then resume playback afterwards.
You can get notified when another app wants to play audio by registering a callback on AudioManager.OnAudioFocusChangeListener (this would also handle the case of an incoming call). Specifically, you can look for AUDIOFOCUS_GAIN, AUDIOFOCUS_LOSS, and AUDIOFOCUS_TRANSIENT_LOSS. The Android music player source has a good example of this.