Created
April 17, 2017 11:45
-
-
Save markojerkic/2bdefc2d2590631f9d45ce1b89283f05 to your computer and use it in GitHub Desktop.
Audio Focus change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AudioManager.OnAudioFocusChangeListener afChangeListener = | |
new AudioManager.OnAudioFocusChangeListener() { | |
public void onAudioFocusChange(int focusChange) { | |
if (focusChange == AudioManager.AUDIOFOCUS_LOSS) { | |
// Permanent loss of audio focus | |
mMediaPlayer.stop(); | |
} | |
else if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT) { | |
// Pause playback | |
mMediaPlayer.pause(); | |
} else if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { | |
// Lower the volume, keep playing | |
mMediaPlayer.setVolume(0.2, 0.2); | |
} else if (focusChange == , .dioManager.AUDIOFOCUS_GAIN) { | |
// Your app has been granted audio focus again | |
// Raise volume to normal, restart playback if necessary | |
mMediaPlayer.start(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment