Note that there are some explanatory texts on larger screens.

plurals
  1. POonAudioFocusChange not called
    primarykey
    data
    text
    <pre><code>private static int changedFocus; private static boolean focusGranted; private static AudioManager audioManager; public static int getChangedFocus() { return changedFocus; } public static boolean isFocusGranted() { return focusGranted; } public static void requestFocus(final Context context) { if (audioManager == null) { audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } switch (audioManager.requestAudioFocus(OnFocusChangeListener.getInstance(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN)) { case AudioManager.AUDIOFOCUS_REQUEST_GRANTED: focusGranted = true; break; case AudioManager.AUDIOFOCUS_REQUEST_FAILED: focusGranted = false; break; } } private static final class OnFocusChangeListener implements AudioManager.OnAudioFocusChangeListener { private static OnFocusChangeListener instance; protected static OnFocusChangeListener getInstance() { if (instance == null) { instance = new OnFocusChangeListener(); } return instance; } @Override public void onAudioFocusChange(final int focusChange) { changedFocus = focusChange; System.out.println("on focus change: " + focusChange); switch (focusChange) { case AudioManager.AUDIOFOCUS_GAIN: GlobalMusicPlayer.onFocusGained(); break; case AudioManager.AUDIOFOCUS_LOSS: GlobalMusicPlayer.onFocusLoss(); break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: GlobalMusicPlayer.onFocusLossTransient(); break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: GlobalMusicPlayer.onFocusLossTransientCanDuck(); break; } } } </code></pre> <p>I call requestFocus(context) and get AudioManager.AUDIOFOCUS_REQUEST_GRANTED as a return value.</p> <p>After that, <strong>onAudioFocusChange</strong> never called and thus <strong>changedFocus</strong> is always 0.</p> <pre><code>isFocusGranted() // true getChangedFocus() // 0 </code></pre> <p>Devices: Nexus 10, Motorola Xoom.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload