Reputation: 8453
I am trying to pause any music that is already playing in the Android device that uses default music player. I went over Android doc http://developer.android.com/training/managing-audio/audio-focus.html . I can pause music when I want, but I am not able to resume the previously paused music after my work is done, although I use am.abandonAudioFocus(afChangeListener);
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
// Request audio focus for playback
int result = am.requestAudioFocus(mAudioFocusListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
mPlayer.start();
}
Once my tone stops I call am.abandonAudioFocus(mAudioFocusListener)
and unable to achieve this.
Upvotes: 2
Views: 761
Reputation: 526
Instead of using AudioManager.AUDIOFOCUS_GAIN try AudioManager.AUDIOFOCUS_GAIN_TRANSIENT.
Upvotes: 4