0

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();
  1. 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

vimuth
  • 5,064
  • 33
  • 79
  • 116
bharath gangupalli
  • 550
  • 1
  • 7
  • 23

2 Answers2

0

I tried it out here and gaining/receiving audio focus works on Google TV. The issue might be that the app that was running before your app is not releasing audio focus.

  • if u don mind, can u add the code for it. I tried it but not working...The before app is the Tv running... will it not loses the audio focus? – bharath gangupalli Jul 02 '12 at 04:36
0

Audio focus does work on Google TV but not all applications respect audio focus. I wrote a blog post about how to utilize Audio Focus properly (http://android-developers.blogspot.com/2013/08/respecting-audio-focus.html) but there is no solution for applications that ignore it or do not use audio focus.

Krispy
  • 1,098
  • 1
  • 7
  • 11