0

当电视正在播放频道并且我的应用程序启动并在进入后台时失去焦点时,我需要我的应用程序来获得音频焦点。我试过了,但不能在谷歌电视上工作。我试过 mAudioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN); 它在 device.ie 中工作的音乐在应用程序启动时停止。但不适用于带有任何参数的谷歌电视。音频焦点的步骤是:

1.在主应用程序中

 AudioManager  mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
requestFocus();
  1. 在 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:
            }
        }

任何人都可以在这方面帮助我。谁在谷歌电视中做了音频焦点。

谢谢,巴拉特

4

2 回答 2

0

我在这里尝试过,并在 Google TV 上获得/接收音频焦点。问题可能是在您的应用程序之前运行的应用程序没有释放音频焦点。

于 2012-06-29T20:35:36.750 回答
0

音频焦点确实适用于 Google TV,但并非所有应用程序都尊重音频焦点。我写了一篇关于如何正确使用音频焦点的博客文章(http://android-developers.blogspot.com/2013/08/respecting-audio-focus.html),但是对于忽略或不忽略它的应用程序没有解决方案使用音频焦点。

于 2013-09-03T17:17:44.933 回答