I have an app that uses Text To Speech, and also allows the user to call up their music player. [for now I'm trying to avoid coding my own player] I would like to lower the volume or pause the music being play in the background [not my app] while my TTP is talking.
I was able to request sound focus using AudioManager just before my TTS, but then I don't know how to give it back. I have been searching for a while and I can't seem to get it right.
I appreciate any help you can give me, Thank you.
PS: I am aiming for Android version 2.2+
...
//Intent to load player
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
...
//requesting focus
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
these are some of the links I have look and gotten me closer [I think]
Call
abandonAudioFocus()
.