Created
April 6, 2016 17:44
-
-
Save anonymous/6d00bb2e8524fb78bb50f118a6180b8a to your computer and use it in GitHub Desktop.
Miwok app: OnAudioFocusChangeListener declaration from NumberActivity
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
/** | |
* This listener gets triggered whenever the audio focus changes | |
* (i.e., we gain or lose audio focus because of another app or device). | |
*/ | |
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() { | |
@Override | |
public void onAudioFocusChange(int focusChange) { | |
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || | |
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { | |
// The AUDIOFOCUS_LOSS_TRANSIENT case means that we've lost audio focus for a | |
// short amount of time. The AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK case means that | |
// our app is allowed to continue playing sound but at a lower volume. We'll treat | |
// both cases the same way because our app is playing short sound files. | |
// Pause playback and reset player to the start of the file. That way, we can | |
// play the word from the beginning when we resume playback. | |
mMediaPlayer.pause(); | |
mMediaPlayer.seekTo(0); | |
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { | |
// The AUDIOFOCUS_GAIN case means we have regained focus and can resume playback. | |
mMediaPlayer.start(); | |
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) { | |
// The AUDIOFOCUS_LOSS case means we've lost audio focus and | |
// Stop playback and clean up resources | |
releaseMediaPlayer(); | |
} | |
} | |
}; |
Hi All,
After initializing the AudioManager reference variable , to get the AUDIO_SERVICE S i am using below code. i am getting the Context unable to recognize.
mAudioManager is private global variable.
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); could you please help me.Thanks & Regards,
Yeswanth.
try using mAudioManager=(AudioManager) contextActivity.getSystemService(Context.AUDIO_SERVICE);
Does someone have a problem with deprecations, how did you solve it?
mAudioManager.registerMediaButtonEventReciever(); ????
Nice code up there!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did use a switch statement for different audio focus states