Code example for AudioManager

Methods: requestAudioFocus

0
    this.service = new WeakReference<StreamingPlaybackService>(service);
  } 
 
  @Override 
  public void requestFocus() { 
    audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
  } 
 
  @Override 
  public void onAudioFocusChange(final int focusChange) {
    final StreamingPlaybackService service = this.service.get();
    if (service == null) { return; }
    switch (focusChange) {
    case AudioManager.AUDIOFOCUS_LOSS:
      service.stop();
      break; 
    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
    case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
      service.calmDown();
      break; 
    case AudioManager.AUDIOFOCUS_GAIN: