Example usage for android.media AudioManager AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

List of usage examples for android.media AudioManager AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

Introduction

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

Prototype

int AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

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

Click Source Link

Document

Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, during which no other applications, or system components, should play anything.

Usage

From source file:com.ironsmile.cordova.mediaevents.MediaEventListener.java

/**
 * Updates the JavaScript side with new audio focus event
 *
 * @param focusEvent the received event//from   w  w w.  java2 s  .  c  o m
 * @return
 */
private void sendFocusEvent(int focusEvent) {
    JSONObject obj = new JSONObject();
    try {
        switch (focusEvent) {
        case AudioManager.AUDIOFOCUS_GAIN:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            obj.put("type", "audiofocusgain");
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            obj.put("type", "audiofocusloss");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            obj.put("type", "audiofocuslosstransient");
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            obj.put("type", "audiofocuslosstransientcanduck");
            break;
        }

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    sendUpdate(obj, true);
}

From source file:androidx.media.widget.VideoView2.java

/**
 * 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./* www  . j av a 2s  .  c o m*/
 *
 * @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;
}