Hi all,

I am developing an application, where i need to capture the timestamp of
music starts and ends. For that have used OnAudioFocusChangeListener, and
request for AUDIO_GAIN event. Below is my code.

public class AudioManagerExample extends Activity implements
 OnAudioFocusChangeListener{

   public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);

        int result = am.requestAudioFocus(this,AudioManager.STREAM_MUSIC
,AudioManager.AUDIOFOCUS_GAIN);

        if(result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED)

        Log.d("AudioManager", "Request Granted");

      }

  @Override

   public void onAudioFocusChange(int focusChange) {

     if(focusChange == AudioManager.AUDIOFOCUS_GAIN)

            Log.d("AudioManager", "Inside on audio focus gained " );

    else if(focusChange == AudioManager.AUDIOFOCUS_LOSS)

            Log.d("AudioManager", "Inside on audio focus lossed ");

     }

}
onAudioFocusChange function get called when i play the music, am getting
"audio focus lossed" message instead of gain message and I checked the
focusChange value it is -1. Also listener will be called only once i.e when
i opened the music first time. Listener is not called If music player is
closed and opened again.  Why is this so?  Do i need to add any permission?
I had surfed a lot but not get the proper solution Please anybody could
explain?

Thanks
Pushpa

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to