rdio / api

A public issue tracker for the Rdio API
http://www.rdio.com/developers/
26 stars 3 forks source link

Android app audio focus loss should be permanent #90

Open OldSneerJaw opened 11 years ago

OldSneerJaw commented 11 years ago

The Rdio Android app does not conform to the Android API's guidelines on handling permanent loss of audio focus. Specifically, it should abandon audio focus when its OnAudioFocusChangeListener receives an AudioManager.AUDIOFOCUS_LOSS event. Currently, as implemented, it merely pauses, and then resumes playback as soon as audio focus is abandoned by all other apps.

This is proving problematic for me because I am trying to build a simple music sleep timer app (i.e. stop all media players after X minutes). When my app requests audio focus, Rdio pauses playback as expected. But, even if my app tries to hold onto audio focus, after a few minutes, it will be killed by the system (as per the Process Lifecycle) and Rdio's playback will resume because it hasn't abandoned audio focus. There are workarounds (e.g. use a service to hold onto audio focus indefinitely), but it works well with other music apps (e.g. Google Play Music) and I'd rather not have to use a hack just for Rdio.

A relevant quote from the Android API guideline Handle the Loss of Audio Focus:

If the audio focus loss is permanent, it’s assumed that another application is now being used to listen to audio and your app should effectively end itself. In practical terms, that means stopping playback, removing media button listeners—allowing the new audio player to exclusively handle those events—and abandoning your audio focus. At that point, you would expect a user action (pressing play in your app) to be required before you resume playing audio.

And a code example from the same guideline document:

OnAudioFocusChangeListener afChangeListener = new OnAudioFocusChangeListener() {
    public void onAudioFocusChange(int focusChange) {
        if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT
            // Pause playback
        } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
            // Resume playback 
        } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
            am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
            am.abandonAudioFocus(afChangeListener);
            // Stop playback
        }
    }
};
dasevilla commented 11 years ago

Thanks for the report! The someone from the mobile team is looking into it.