Java Code Examples for android.media.AudioManager#AUDIOFOCUS_NONE

The following examples show how to use android.media.AudioManager#AUDIOFOCUS_NONE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FocusRequester.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Class constructor
 * @param aa
 * @param focusRequest
 * @param grantFlags
 * @param afl
 * @param source
 * @param id
 * @param hdlr
 * @param pn
 * @param uid
 * @param ctlr cannot be null
 */
FocusRequester(AudioAttributes aa, int focusRequest, int grantFlags,
        IAudioFocusDispatcher afl, IBinder source, String id, AudioFocusDeathHandler hdlr,
        String pn, int uid, @NonNull MediaFocusControl ctlr, int sdk) {
    mAttributes = aa;
    mFocusDispatcher = afl;
    mSourceRef = source;
    mClientId = id;
    mDeathHandler = hdlr;
    mPackageName = pn;
    mCallingUid = uid;
    mFocusGainRequest = focusRequest;
    mGrantFlags = grantFlags;
    mFocusLossReceived = AudioManager.AUDIOFOCUS_NONE;
    mFocusLossWasNotified = true;
    mFocusController = ctlr;
    mSdkTarget = sdk;
}
 
Example 2
Source File: FocusRequester.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
FocusRequester(AudioFocusInfo afi, IAudioFocusDispatcher afl,
         IBinder source, AudioFocusDeathHandler hdlr, @NonNull MediaFocusControl ctlr) {
    mAttributes = afi.getAttributes();
    mClientId = afi.getClientId();
    mPackageName = afi.getPackageName();
    mCallingUid = afi.getClientUid();
    mFocusGainRequest = afi.getGainRequest();
    mFocusLossReceived = AudioManager.AUDIOFOCUS_NONE;
    mFocusLossWasNotified = true;
    mGrantFlags = afi.getFlags();
    mSdkTarget = afi.getSdkTarget();

    mFocusDispatcher = afl;
    mSourceRef = source;
    mDeathHandler = hdlr;
    mFocusController = ctlr;
}
 
Example 3
Source File: FocusRequester.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static String focusChangeToString(int focus) {
    switch(focus) {
        case AudioManager.AUDIOFOCUS_NONE:
            return "none";
        case AudioManager.AUDIOFOCUS_GAIN:
            return "GAIN";
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            return "GAIN_TRANSIENT";
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            return "GAIN_TRANSIENT_MAY_DUCK";
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
            return "GAIN_TRANSIENT_EXCLUSIVE";
        case AudioManager.AUDIOFOCUS_LOSS:
            return "LOSS";
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            return "LOSS_TRANSIENT";
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            return "LOSS_TRANSIENT_CAN_DUCK";
        default:
            return "[invalid focus change" + focus + "]";
    }
}
 
Example 4
Source File: FocusRequester.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@GuardedBy("MediaFocusControl.mAudioFocusLock")
void handleFocusGain(int focusGain) {
    try {
        mFocusLossReceived = AudioManager.AUDIOFOCUS_NONE;
        mFocusController.notifyExtPolicyFocusGrant_syncAf(toAudioFocusInfo(),
                AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
        final IAudioFocusDispatcher fd = mFocusDispatcher;
        if (fd != null) {
            if (DEBUG) {
                Log.v(TAG, "dispatching " + focusChangeToString(focusGain) + " to "
                    + mClientId);
            }
            if (mFocusLossWasNotified) {
                fd.dispatchAudioFocusChange(focusGain, mClientId);
            }
        }
        mFocusController.unduckPlayers(this);
    } catch (android.os.RemoteException e) {
        Log.e(TAG, "Failure to signal gain of audio focus due to: ", e);
    }
}
 
Example 5
Source File: MediaFocusControl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
protected int getCurrentAudioFocus() {
    synchronized(mAudioFocusLock) {
        if (mFocusStack.empty()) {
            return AudioManager.AUDIOFOCUS_NONE;
        } else {
            return mFocusStack.peek().getGainRequest();
        }
    }
}
 
Example 6
Source File: FocusRequester.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * For a given audio focus gain request, return the audio focus loss type that will result
 * from it, taking into account any previous focus loss.
 * @param gainRequest
 * @return the audio focus loss type that matches the gain request
 */
private int focusLossForGainRequest(int gainRequest) {
    switch(gainRequest) {
        case AudioManager.AUDIOFOCUS_GAIN:
            switch(mFocusLossReceived) {
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                case AudioManager.AUDIOFOCUS_LOSS:
                case AudioManager.AUDIOFOCUS_NONE:
                    return AudioManager.AUDIOFOCUS_LOSS;
            }
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            switch(mFocusLossReceived) {
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                case AudioManager.AUDIOFOCUS_NONE:
                    return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT;
                case AudioManager.AUDIOFOCUS_LOSS:
                    return AudioManager.AUDIOFOCUS_LOSS;
            }
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            switch(mFocusLossReceived) {
                case AudioManager.AUDIOFOCUS_NONE:
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                    return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                    return AudioManager.AUDIOFOCUS_LOSS_TRANSIENT;
                case AudioManager.AUDIOFOCUS_LOSS:
                    return AudioManager.AUDIOFOCUS_LOSS;
            }
        default:
            Log.e(TAG, "focusLossForGainRequest() for invalid focus request "+ gainRequest);
                    return AudioManager.AUDIOFOCUS_NONE;
    }
}
 
Example 7
Source File: VideoView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void onCompletion(MediaPlayer mp) {
    mCurrentState = STATE_PLAYBACK_COMPLETED;
    mTargetState = STATE_PLAYBACK_COMPLETED;
    if (mMediaController != null) {
        mMediaController.hide();
    }
    if (mOnCompletionListener != null) {
        mOnCompletionListener.onCompletion(mMediaPlayer);
    }
    if (mAudioFocusType != AudioManager.AUDIOFOCUS_NONE) {
        mAudioManager.abandonAudioFocus(null);
    }
}
 
Example 8
Source File: VideoView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void release(boolean cleartargetstate) {
    if (mMediaPlayer != null) {
        mMediaPlayer.reset();
        mMediaPlayer.release();
        mMediaPlayer = null;
        mPendingSubtitleTracks.clear();
        mCurrentState = STATE_IDLE;
        if (cleartargetstate) {
            mTargetState  = STATE_IDLE;
        }
        if (mAudioFocusType != AudioManager.AUDIOFOCUS_NONE) {
            mAudioManager.abandonAudioFocus(null);
        }
    }
}
 
Example 9
Source File: VideoView.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets which type of audio focus will be requested during the playback, or configures playback
 * to not request audio focus. Valid values for focus requests are
 * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT},
 * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and
 * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use
 * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be
 * requested when playback starts. You can for instance use this when playing a silent animation
 * through this class, and you don't want to affect other audio applications playing in the
 * background.
 * @param focusGain the type of audio focus gain that will be requested, or
 *    {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during playback.
 */
public void setAudioFocusRequest(int focusGain) {
    if (focusGain != AudioManager.AUDIOFOCUS_NONE
            && focusGain != AudioManager.AUDIOFOCUS_GAIN
            && focusGain != AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
            && focusGain != AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
            && focusGain != AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) {
        throw new IllegalArgumentException("Illegal audio focus type " + focusGain);
    }
    mAudioFocusType = focusGain;
}