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:com.mishiranu.dashchan.content.service.AudioPlayerService.java

private boolean play(boolean resetFocus) {
    if (resetFocus && audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN) != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        return false;
    }//from   ww w . ja v a2  s.co  m
    mediaPlayer.start();
    wakeLock.acquire();
    return true;
}

From source file:com.appdevper.mediaplayer.app.LocalPlayback.java

/**
 * Try to get the system audio focus.//  w w w.  j  av a2  s.  c  o m
 */
private void tryToGetAudioFocus() {
    LogHelper.d(TAG, "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:com.example.android.supportv4.media.Playback.java

/**
 * Give up the audio focus.// w ww  .j  a v a 2 s . c  o m
 */
private void giveUpAudioFocus() {
    Log.d(TAG, "giveUpAudioFocus");
    if (mAudioFocus == AUDIO_FOCUSED) {
        if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
        }
    }
}

From source file:com.appdevper.mediaplayer.app.LocalPlayback.java

/**
 * Give up the audio focus.//w w  w. ja  va 2s .c  o  m
 */
private void giveUpAudioFocus() {
    LogHelper.d(TAG, "giveUpAudioFocus");
    if (mAudioFocus == AUDIO_FOCUSED) {
        if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
        }
    }
}

From source file:com.example.android.uamp.playback.LocalPlayback.java

/**
 * Try to get the system audio focus.//from ww w . j  av a2s .c o m
 */
private void tryToGetAudioFocus() {
    LogHelper.d(TAG, "tryToGetAudioFocus");
    int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mAudioFocus = AUDIO_FOCUSED;
    } else {
        mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    }
}

From source file:com.example.android.uamp.playback.LocalPlayback.java

/**
 * Give up the audio focus.//from  www . j  a  v  a2  s  . co  m
 */
private void giveUpAudioFocus() {
    LogHelper.d(TAG, "giveUpAudioFocus");
    if (mAudioManager.abandonAudioFocus(this) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mAudioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    }
}

From source file:com.murati.oszk.audiobook.playback.LocalPlayback.java

private void tryToGetAudioFocus() {
    LogHelper.d(TAG, "tryToGetAudioFocus");
    int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mCurrentAudioFocusState = AUDIO_FOCUSED;
    } else {//from  w ww. ja  va 2 s .  c  om
        mCurrentAudioFocusState = AUDIO_NO_FOCUS_NO_DUCK;
    }
}

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

private void tryToGetAudioFocus() {
    Timber.d("tryToGetAudioFocus");
    int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        audioFocus = AUDIO_FOCUSED;/*from   w w  w  . j a  va  2  s . co m*/
    } else {
        audioFocus = AUDIO_NO_FOCUS_NO_DUCK;
    }
}

From source file:org.y20k.transistor.PlayerService.java

private boolean requestFocus() {
    int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}

From source file:com.murati.oszk.audiobook.playback.LocalPlayback.java

private void giveUpAudioFocus() {
    LogHelper.d(TAG, "giveUpAudioFocus");
    if (mAudioManager
            .abandonAudioFocus(mOnAudioFocusChangeListener) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mCurrentAudioFocusState = AUDIO_NO_FOCUS_NO_DUCK;
    }/*  www .  j a  v  a 2 s  .  c  o  m*/
}