簡體   English   中英

當電視在Google TV中運行時,音頻會集中在我的應用程序上

[英]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();
  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:
            }
        }

誰能幫我這個忙。 誰在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM