我需要我的应用程序来获取音频焦点,当电视正在推出一个频道时我的应用程序启动并且当它转到后台时松散焦点。我尝试过,但没有在谷歌电视台工作。 我试过mAudioManager.requestAudioFocus(这个,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN); 它工作在device.i.e音乐停止应用程序启动。但没有在任何参数的谷歌电视工作。 音频焦点的步骤是:
1.在MainApp
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
requestFocus();
在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. 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:
}
}
任何人都可以帮助我。谁在谷歌电视上做了音频聚焦。
谢谢Bharath
答案 0 :(得分:0)
我在这里试了一下,在Google TV上获得/接收音频焦点。问题可能是应用程序之前运行的应用程序未释放音频焦点。
答案 1 :(得分:0)
音频焦点适用于Google TV,但并非所有应用都支持音频焦点。我写了一篇关于如何正确使用音频焦点的博客文章(http://android-developers.blogspot.com/2013/08/respecting-audio-focus.html),但对于忽略它或不使用音频焦点的应用程序没有解决方案。