Skip to content

Commit

Permalink
Improve Android Audio Focus (TheWidlarzGroup#1897)
Browse files Browse the repository at this point in the history
Implement audio focus as per android docs:
https://developer.android.com/guide/topics/media-apps/audio-focus
https://medium.com/androiddevelopers/audio-focus-3-cdc09da9c122

AUDIOFOCUS_LOSS should abandon focus and not try resuming audio, this is done with AUDIOFOCUS_LOSS_TRANSIENT

This fixes at least:
- Audio not being paused after focus being taken by some voip applications
- Content resuming and pausing instantly sporadically (some race condition perhaps) when activity was resumed from background.
  • Loading branch information
michaeltintiuc committed Feb 17, 2020
1 parent 2738892 commit 82c191d
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,11 @@ private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
eventEmitter.audioFocusChanged(false);
pausePlayback();
audioManager.abandonAudioFocus(this);
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
eventEmitter.audioFocusChanged(false);
break;
case AudioManager.AUDIOFOCUS_GAIN:
Expand Down

0 comments on commit 82c191d

Please sign in to comment.