[英]Audio focus on my app when tv is running in google tv
当我在电视上浏览频道并启动应用程序时,我需要我的应用程序来获得音频焦点,而在背景播放时,我需要我的应用程序并释放焦点。 我试过了,但无法在Google电视上工作。 我尝试了mAudioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN); 它在device.ie中运行,即音乐随着应用程序启动而停止。 但不适用于带有任何参数的Google TV。 进行音频聚焦的步骤是:
1.在MainApp中
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
requestFocus();
在onresume()中
protected void onResume() { super.onResume(); requestFocus(); }
3.在onStop()
protected void onStop(){
abandonFocus();
super.onStop();
Log.e("APPLICATION", "APPLICATION onStop");
}
4.在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:
}
}
谁能帮我这个忙。 谁在Google电视中做了音频焦点。
谢谢,巴拉斯
我在这里尝试过,并在Google TV上获得/接收音频焦点。 问题可能出在您的应用之前运行的应用未释放音频焦点。
音频焦点确实可以在Google TV上使用,但并非所有应用程序都支持音频焦点。 我写了一篇有关如何正确使用Audio Focus的博客文章( http://android-developers.blogspot.com/2013/08/respecting-audio-focus.html ),但是对于忽略或不忽略它的应用程序没有解决方案使用音频焦点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.