Created
August 13, 2013 03:40
-
-
Save seiji/6217711 to your computer and use it in GitHub Desktop.
Managing Audio Focus
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 audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); | |
audioManager.requestAudioFocus(new AudioService(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); |
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
public class AudioService extends Service implements AudioManager.OnAudioFocusChangeListener { | |
@Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
@Override | |
public void onAudioFocusChange(int focusChange) { | |
switch (focusChange) { | |
case AudioManager.AUDIOFOCUS_GAIN: | |
break; | |
case AudioManager.AUDIOFOCUS_LOSS: | |
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: | |
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: | |
// audio pause | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment