I need my app to get the audio focus when tv is ruuing a channel and my app is launched and loose focus when it goes to background. I tried it but not working in google tv. I tried mAudioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN); It working in device.i.e music stopped as app launched. but not worked in google tv with any parameters. Steps for audio focus are:
1.In MainApp
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
requestFocus();
In onresume()
protected void onResume() { super.onResume(); requestFocus(); }
3.in onStop()
protected void onStop(){
abandonFocus();
super.onStop();
Log.e("APPLICATION", "APPLICATION onStop");
}
4.in onDestroy()
public void onDestroy(){
super.onDestroy();
//Log.e("APPLICATION", "APPLICATION onDestroy");
abandonFocus();
}
5.Methods for AudioFocus.
/** Requests audio focus. Returns whether request was successful or not. */
public boolean requestFocus() {
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED ==
mAudioManager.requestAudioFocus(this, AudioManager.STREAM_DTMF, AudioManager.AUDIOFOCUS_GAIN);
}
/** Abandons audio focus. Returns whether request was successful or not. */
public boolean abandonFocus() {
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this);
}
/**
* Called by AudioManager on audio focus changes. We implement this by calling our
* MusicFocusable appropriately to relay the message.
*/
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
Log.e("AUDIOFOCUS","AUDIOFOCUS_GAIN");
break;
case AudioManager.AUDIOFOCUS_LOSS:Log.e("AUDIOFOCUS","AUDIOFOCUS_LOSS");
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:Log.e("AUDIOFOCUS","AUDIOFOCUS_LOSS_TRANSIENT");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:Log.e("AUDIOFOCUS","AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
break;
default:
}
}
Can any one please help me in this. who did the audio focus in google tv.
Thanks, Bharath