Is is possible to have more than one AudioFocus in one app on Android?

Viewed 147

I'm developing an android app which will play both audio file(via MediaPlayer), and TextToSpeech. Each will have specific timing for playing. While audio is playing, if TTS speaking time comes, I want to lower the volume of MediaPlayer. Also, while TTS is speaking, if audio playing time comes, I want to lower the volume of TTS. (Both using AudioManager.STREAM_MUSIC)

I wanted to use something similar to AudioFocus(like below code). Behavior like requesting audio focus with AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK would be perfect, but both MediaPlayer and TTS is in same app, so it wouldn't duck the other sound.

I was wondering if somehow I can have different AudioFocus for each MediaPlayer and TTS, so that I can duck the sound while playing the other sound..

I could manage to manually lower the volume of MediaPlayer, but I found it almost impossible to programmatically lower the volume of TTS while it is already playing.

Any other suggestion besides using AudioFocus, AudioMAanger to solve this problem would be helpful too.

0 Answers
Related