How to make background sound quiter - android

If you have an app like Spotify playing music in a background and try to listen to some sound in Google Chrome at the same moment, the background music becomes quieter at this very moment while Chrome playing the sound and then comes back to normal level.
I am wondering how I can do the same from my own Android app, namely, to make volume of all other applications lower for some time, but allow my application to play sounds with normal volume at the same time. I tried to find the answer, but usually all recommendations are about how to change volume globally.

This is a feature called audio ducking- the sound that gets quieter is said to be ducked. The way Android does it is through audio focus. Your app needs to request focus, and the other app's sound will be changed appropriately. The documentation on it is at https://developer.android.com/guide/topics/media-apps/audio-focus. The mechanism changed in Android 12, so you'll likely have to have different code for older versions and newer ones to make it all work.

Related

Openvidu subscriber volume on android

So using openvidu to setup two way calling but I noticed an issue when it’s being used on an android device.
The android phone has multiple volume controls, one of them is the media volume, so if the user watching as a subscriber has their media volume low they can’t hear the publisher speaking until they turn it up, and a few people don’t even know this exists.
By default the volume up hardware button seems to control the phone volume, or rather it seems to control the last one that was used.
It’s a little concerning that many people won’t know about this and will complain they can’t hear anything, unlike on the iPhone where the one button controls the overall volume.
I doubt this is possible but are we able to increase the android media volume
With JavaScript somehow? I very much doubt it but I’m not sure how to solve this problem if we can’t. I know we can control the video element volume itself but that seems to have no impact on the phone volume itself. As in I can turn the phone media volume all the way up but control the video element separate instead of them working together.

How can I use call sound not media sound with agora on the android web browser?

On Android Web Browser (Chrome or other browsers as well), the sound comes out to media sound, not the call sound. (in Demo too)
So, when the user controls the volume up/down buttons, it controls the call sound not the media sound. So, this misleads the users behaviours and it cause a lot of uncomfortable situations. And it's a bit difficult to control it on old android devices. Is there any way to solve this problem?
I tried with appRTC demo(https://appr.tc/). And the sound comes out to the call sound. And I can control the volume with the volume up/down buttons.
Please help me out. Thanks.
There isn't an API method to play audio as a call volume on the Agora Web SDK as of now. Media volume is the intended way of playing media on the browser. If you want to use the call volume you can check out the Android SDK instead.

SoundCloud HTML5 Widget API - Play Not Working in Chrome for Android

You can see the player live here:
www.stateofpsychosis.com/media/
The viewable player is a custom player. The default SC player has been shrunk down to a 1x1px iframe so it can't be seen without using the developer tools to make changes to the style.
This is only a problem on Chrome for Android
For some reason I can't get the API to actually play the music. The Previous/Next buttons work in the sense that they query and change the info, but they won't play the song either. It does however change the default SoundCloud widget play button to a pause button. It changes the track info. But it just won't actually make any noise. If I make the widget viewable and push anything in the default player (as opposed to the custom one), it seems to work though.
I too, am facing the same issue.
It seems that Chrome for Android restricts the ability to trigger HTML5 audio playing. This is to protect users from extra data usage on their phones. It seems that triggering the audio to play from a script is not allowed.
You can read more about the issue
here
Hopefully they lift this restriction in the near future.

How can I auto-pause the audio player in my app when another app starts to play audio?

My app plays an audio file. I want my app to pause the audio playing if another apps starts to play audio. I don't want the two audio sounds mess up each other. My app will resume the audio playing after the other app finishes playing its audio. How can I make it? Thanks.
Depending on how your application is running ie. while app is running in foreground (users is looking at your screen) or if your running a "service" which is currently in the background and you wish music to continue playing (songza, slacker radio etc.) how you handle these things will be different. Android uses internal system states to determine which apps should be out-putting audio to the speaker. All this is handled by the audio manager requestAudioFocus() releaseAudioFocus() will be the system calls you will want to look at the most. For a more detailed explanation see android developer api where you this is explained and documented quite well http://developer.android.com/guide/topics/media/mediaplayer.html

Android: Detect another application has started playing audio

My music application constantly plays music in the background, however I'd like to be able to detect when another application starts playing audio (such as the YouTube app) so I can pause/mute/stop the audio in my application.
This will allow a user to continue browsing the web whilst listening to music, but then if they wish to watch a video at any point, they can do so without audio conflict.
One solution might be to listen for a broadcast which states when an application begins using the AudioManager. Does such an Intent Action exist?
Edit: As in the answer provided below, there appears to be a method of detecting the loss of audio focus in 2.2 with AudioManager.OnAudioFocusChangeListener.
Great, but is there a solution for the more common versions of Android? Ideally 1.5+.
http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html
this thread also has additional information that might get you heading in the right direction.
http://groups.google.com/group/android-developers/browse_thread/thread/db6822d84feaac6/219d8cba07795c61?hl=en&lnk=gst&q=OnAudioFocusChangeListener#219d8cba07795c61

Categories

Resources