tlenclos / react-native-audio-streaming

iOS & Android react native module to play an audio stream, with background support and media controls
MIT License
781 stars 255 forks source link

Android - Audio Focus Request & Wait #123

Closed scgough closed 2 weeks ago

scgough commented 6 years ago

I noticed that on Android, sound can overlap between applications so this addition will use AudioManager to request audio focus and play the sound after it has been granted.

fidelsam1992 commented 5 years ago

Thank you for this PR it is really helpful.

In case you also need to resume the streaming automatically after the call is done, or the other app using audio is closed. Use this code below under in file ReactNativeAudioStreamingModule.java

case (AudioManager.AUDIOFOCUS_GAIN) :
                  // Return the volume to normal and resume if paused.
                  playInternal();
                  break;
                default: break;