Every app that plays audio must get the audio session before playing the audio
for this the code is as below
private void requestAudioFocusAndStartPlayer(boolean isResume)
{
abandonAudioFocus();
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
if(mAudioManager != null)
{
int result = mAudioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if(result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
{
Log.i(TAG,"Audio Focus request not granted result:"+result);
stopPlayer();
}
else
{
if(isResume) {
resumePlayer();
}
else
{
startPlayer();
}
}
}
}
references:
No comments:
Post a Comment