Example usage for android.media AudioManager AUDIOFOCUS_REQUEST_GRANTED

List of usage examples for android.media AudioManager AUDIOFOCUS_REQUEST_GRANTED

Introduction

In this page you can find the example usage for android.media AudioManager AUDIOFOCUS_REQUEST_GRANTED.

Prototype

int AUDIOFOCUS_REQUEST_GRANTED

To view the source code for android.media AudioManager AUDIOFOCUS_REQUEST_GRANTED.

Click Source Link

Document

A successful focus change request.

Usage

From source file:net.simno.klingar.playback.LocalPlayback.java

private void giveUpAudioFocus() {
    Timber.d("giveUpAudioFocus");
    if (audioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        audioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    }/*www  .j a  va2 s  . c  o m*/
}

From source file:nuclei.media.playback.FallbackPlayback.java

/**
 * Try to get the system audio focus./*  w  ww  . j  ava  2 s.  co m*/
 */
private void tryToGetAudioFocus() {
    if (mAudioFocus != AUDIO_FOCUSED) {
        int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_FOCUSED;
        }
    }
}

From source file:nuclei.media.playback.FallbackPlayback.java

/**
 * Give up the audio focus.// w w w .  ja va2s.  co  m
 */
private void giveUpAudioFocus() {
    if (mAudioFocus == AUDIO_FOCUSED) {
        if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
        }
    }
}

From source file:dk.nota.lyt.libvlc.PlaybackService.java

private void changeAudioFocus(boolean acquire) {
    final AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (am == null)
        return;/*from  w w  w. j  av a2  s  .c  om*/

    if (acquire) {
        if (!mHasAudioFocus) {
            final int result = am.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
                    AudioManager.AUDIOFOCUS_GAIN);
            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                am.setParameters("bgm_state=true");
                mHasAudioFocus = true;
            }
        }
    } else {
        if (mHasAudioFocus) {
            final int result = am.abandonAudioFocus(mAudioFocusListener);
            am.setParameters("bgm_state=false");
            mHasAudioFocus = false;
        }
    }
}

From source file:nuclei.media.playback.ExoPlayerPlayback.java

/**
 * Try to get the system audio focus./*  www  .  j a v  a2 s .  c  om*/
 */
private void tryToGetAudioFocus() {
    LOG.d("tryToGetAudioFocus");
    if (mAudioFocus != AUDIO_FOCUSED) {
        int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_FOCUSED;
        }
    }
}

From source file:nuclei.media.playback.ExoPlayerPlayback.java

/**
 * Give up the audio focus.//from  w  w  w.j  a  v a2  s  .c  om
 */
private void giveUpAudioFocus() {
    LOG.d("giveUpAudioFocus");
    if (mAudioFocus == AUDIO_FOCUSED) {
        if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
        }
    }
}

From source file:com.namelessdev.mpdroid.NotificationService.java

/**
 * We try to get audio focus, but don't really try too hard.
 * We just want the lock screen cover art.
 *//* w w w .  ja v  a 2 s.  co m*/
private void tryToGetAudioFocus() {
    if ((!app.getApplicationState().streamingMode || StreamingService.isWoundDown()) && !isAudioFocusedOnThis) {
        Log.d(TAG, "requesting audio focus");
        final int result = mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);

        isAudioFocusedOnThis = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
    }
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * Requests AudioFocus from the OS.// w w  w . ja  v a  2  s  . c om
 * 
 * @return True if AudioFocus was gained. False, otherwise.
 */
private boolean requestAudioFocus() {
    int result = mAudioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

    if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        //Stop the service.
        mService.stopSelf();
        Toast.makeText(mContext, R.string.close_other_audio_apps, Toast.LENGTH_LONG).show();
        return false;
    } else {
        return true;
    }

}

From source file:com.owncloud.android.media.MediaService.java

/**
 * Fully releases the audio focus.//from w ww . j a  v  a2  s  .  c o  m
 */
private void giveUpAudioFocus() {
    if (mAudioFocus == AudioFocus.FOCUS && mAudioManager != null
            && AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this)) {

        mAudioFocus = AudioFocus.NO_FOCUS;
    }
}

From source file:com.google.fpl.gim.examplegame.MainService.java

/**
 * Obtain audio focus for the application. This also checks if we are currently playing any
 * other audio clips, so it checks for "audio focus" within the app.
 * @return True if audio focus is obtained. False otherwise.
 *//*  ww w .  j  av  a2 s . co  m*/
public boolean obtainAudioFocus() {
    if (mMediaPlayer.isPlaying() || mTextToSpeech.isSpeaking()) {
        return false;
    }

    int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    return (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
}