Skip to content

Instantly share code, notes, and snippets.

@atlantis0
Last active June 17, 2016 06:56
Show Gist options
  • Save atlantis0/10d085eecf06ca86b51db0caa6db3a75 to your computer and use it in GitHub Desktop.
Save atlantis0/10d085eecf06ca86b51db0caa6db3a75 to your computer and use it in GitHub Desktop.
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
// resume playback,
// it is now safe to continue playing
break;
case AudioManager.AUDIOFOCUS_LOSS:
// Lost focus for an unbounded amount of time: stop playback and release media player
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
// Lost focus for a short time, but we have to stop
// playback. We don't release the media player because playback
// is likely to resume
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
// Lost focus for a short time, but it's ok to keep playing
// at an attenuated level
// Todo - lower volume
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment