Java Code Examples for android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

The following examples show how to use android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK . 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
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 2
Source File: IflySynthesizer.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onAudioFocusChange(int focusChange) {
    Log.e(TAG, "audioFocusChangeListener.onAudioFocusChange>>>>>>>>>>>>>>>>>>" + focusChange);
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // pauseSpeaking();
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            /*if (isSpeaking()) {
                synthesizer.resumeSpeaking();
            }*/
            break;
        default:
            break;
    }
}
 
Example 3
Source File: AudioTrackManagerDualNormal.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
private int getTTSAudioTrackFocus(int ttsType) {
    setTTSType(ttsType);
    if (ttsType == PCMPlayerUtils.TTS_TYPE_VR) {
        return 0;
    }

    int audioFocusType;

    audioFocusType = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;

    int ttsAudioTrackType = VehicleFactoryAdapter.getInstance().getTTSAudioTrackStreamType();
    int result = mAM.requestAudioFocus(mTTSAudioFocusListener, ttsAudioTrackType, audioFocusType);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        LogUtil.d(TAG, "tts audio track get successfully!");

        return 0;
    } else {
        LogUtil.d(TAG, "tts audio track get failed!");

        return -1;
    }

}
 
Example 4
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 5
Source File: FlutterIncallManagerPlugin.java    From flutter-incall-manager with ISC License 5 votes vote down vote up
@Override
public void onAudioFocusChange(final int focusChange) {
    String focusChangeStr;
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            focusChangeStr = "AUDIOFOCUS_GAIN";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            focusChangeStr = "AUDIOFOCUS_LOSS";
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            focusChangeStr = "AUDIOFOCUS_LOSS_TRANSIENT";
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            focusChangeStr = "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK";
            break;
        default:
            focusChangeStr = "AUDIOFOCUS_UNKNOW";
            break;
    }

    Log.d(TAG, "onAudioFocusChange: " + focusChange + " - " + focusChangeStr);
    if (eventSink != null) {
        ConstraintsMap params = new ConstraintsMap();
        params.putString("event", "onAudioFocusChange");
        params.putString("eventText", focusChangeStr);
        params.putInt("eventCode", focusChange);
        eventSink.success(params.toMap());
    }
}
 
Example 6
Source File: AudioTrackManagerDualStreamType.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
private int getTTSAudioTrackFocus(int ttsType) {
    setTTSType(ttsType);

    if (ttsType == PCMPlayerUtils.TTS_TYPE_VR) {
        return 0;
    }

    int audioFocusType;

    // some HU tts play does not need to request audio focus
    if (!VehicleFactoryAdapter.getInstance().isTTSRequestAudioFocus()) {
        return 0;

        /**
         * in the future, more interface to get get VR audio focus status should be used here.
         * <p>
         * if VR audio focus is gained, 0 will be returned;
         * <p>
         * else -1 will be returned;
         */
    }

    audioFocusType = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;

    int result = mAM.requestAudioFocus(mTTSAudioFocusListener, mStreamType, audioFocusType);
    LogUtil.d(TAG, "request audio focus->mStreamType: " + mStreamType);

    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        LogUtil.d(TAG, "tts audio focus get successfully!");

        return 0;
    } else {
        LogUtil.d(TAG, "tts audio focus get failed!");

        return -1;
    }

}
 
Example 7
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 5 votes vote down vote up
@Override
public void onAudioFocusChange(final int focusChange) {
    String focusChangeStr;
    switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
            focusChangeStr = "AUDIOFOCUS_GAIN";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
            break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
            focusChangeStr = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
            break;
        case AudioManager.AUDIOFOCUS_LOSS:
            focusChangeStr = "AUDIOFOCUS_LOSS";
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
            focusChangeStr = "AUDIOFOCUS_LOSS_TRANSIENT";
            break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            focusChangeStr = "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK";
            break;
        default:
            focusChangeStr = "AUDIOFOCUS_UNKNOW";
            break;
    }

    Log.d(TAG, "onAudioFocusChange: " + focusChange + " - " + focusChangeStr);

    WritableMap data = Arguments.createMap();
    data.putString("eventText", focusChangeStr);
    data.putInt("eventCode", focusChange);
    sendEvent("onAudioFocusChange", data);
}
 
Example 8
Source File: AppRTCAudioManager.java    From imsdk-android with MIT License 4 votes vote down vote up
public void start(AudioManagerEvents audioManagerEvents) {
  LogUtil.d(TAG, "start");
  AppRTCUtils.checkIsOnMainThread(apprtcContext);
  if (amState == AudioManagerState.RUNNING) {
    LogUtil.e(TAG, "AudioManager is already active");
    return;
  }
  amState = AudioManagerState.RUNNING;

  // TODO(henrika): perhaps call new method called preInitAudio() here if UNINITIALIZED.

  LogUtil.d(TAG, "AudioManager starts...");
  this.audioManagerEvents = audioManagerEvents;

  // Store current audio state so we can restore it when stop() is called.
  savedAudioMode = audioManager.getMode();
  savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn();
  savedIsMicrophoneMute = audioManager.isMicrophoneMute();
  hasWiredHeadset = hasWiredHeadset();

  // Create an AudioManager.OnAudioFocusChangeListener instance.
  audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
    // Called on the listener to notify if the audio focus for this listener has been changed.
    // The |focusChange| value indicates whether the focus was gained, whether the focus was lost,
    // and whether that loss is transient, or whether the new focus holder will hold it for an
    // unknown amount of time.
    // TODO(henrika): possibly extend support of handling audio-focus changes. Only contains
    // logging for now.
    @Override
    public void onAudioFocusChange(int focusChange) {
      String typeOfChange = "AUDIOFOCUS_NOT_DEFINED";
      switch (focusChange) {
        case AudioManager.AUDIOFOCUS_GAIN:
          typeOfChange = "AUDIOFOCUS_GAIN";
          break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
          typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT";
          break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
          typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
          break;
        case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
          typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
          break;
        case AudioManager.AUDIOFOCUS_LOSS:
          typeOfChange = "AUDIOFOCUS_LOSS";
          break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
          typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT";
          break;
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
          typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK";
          break;
        default:
          typeOfChange = "AUDIOFOCUS_INVALID";
          break;
      }
      LogUtil.d(TAG, "onAudioFocusChange: " + typeOfChange);
    }
  };

  // Request audio playout focus (without ducking) and install listener for changes in focus.
  int result = audioManager.requestAudioFocus(audioFocusChangeListener,
      AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
  if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    LogUtil.d(TAG, "Audio focus request granted for VOICE_CALL streams");
  } else {
    LogUtil.e(TAG, "Audio focus request failed");
  }

  // Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
  // required to be in this mode when playout and/or recording starts for
  // best possible VoIP performance.
  audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

  // Always disable microphone mute during a WebRTC call.
  setMicrophoneMute(false);

  // Set initial device states.
  userSelectedAudioDevice = AudioDevice.NONE;
  selectedAudioDevice = AudioDevice.NONE;
  audioDevices.clear();

  // Initialize and start Bluetooth if a BT device is available or initiate
  // detection of new (enabled) BT devices.
  bluetoothManager.start();

  // Do initial selection of audio device. This setting can later be changed
  // either by adding/removing a BT or wired headset or by covering/uncovering
  // the proximity sensor.
  updateAudioDeviceState();

  // Register receiver for broadcast intents related to adding/removing a
  // wired headset.
  registerReceiver(wiredHeadsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
  LogUtil.d(TAG, "AudioManager started");
}
 
Example 9
Source File: AppRTCAudioManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void start(AudioManagerEvents audioManagerEvents) {
    Log.d(Config.LOGTAG, AppRTCAudioManager.class.getName() + ".start()");
    ThreadUtils.checkIsOnMainThread();
    if (amState == AudioManagerState.RUNNING) {
        Log.e(Config.LOGTAG, "AudioManager is already active");
        return;
    }
    awaitMicrophoneLatch();
    this.audioManagerEvents = audioManagerEvents;
    amState = AudioManagerState.RUNNING;
    // Store current audio state so we can restore it when stop() is called.
    savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn();
    savedIsMicrophoneMute = audioManager.isMicrophoneMute();
    hasWiredHeadset = hasWiredHeadset();
    // Create an AudioManager.OnAudioFocusChangeListener instance.
    audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
        // Called on the listener to notify if the audio focus for this listener has been changed.
        // The |focusChange| value indicates whether the focus was gained, whether the focus was lost,
        // and whether that loss is transient, or whether the new focus holder will hold it for an
        // unknown amount of time.
        // TODO(henrika): possibly extend support of handling audio-focus changes. Only contains
        // logging for now.
        @Override
        public void onAudioFocusChange(int focusChange) {
            final String typeOfChange;
            switch (focusChange) {
                case AudioManager.AUDIOFOCUS_GAIN:
                    typeOfChange = "AUDIOFOCUS_GAIN";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS:
                    typeOfChange = "AUDIOFOCUS_LOSS";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                    typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                    typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK";
                    break;
                default:
                    typeOfChange = "AUDIOFOCUS_INVALID";
                    break;
            }
            Log.d(Config.LOGTAG, "onAudioFocusChange: " + typeOfChange);
        }
    };
    // Request audio playout focus (without ducking) and install listener for changes in focus.
    int result = audioManager.requestAudioFocus(audioFocusChangeListener,
            AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        Log.d(Config.LOGTAG, "Audio focus request granted for VOICE_CALL streams");
    } else {
        Log.e(Config.LOGTAG, "Audio focus request failed");
    }
    // Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
    // required to be in this mode when playout and/or recording starts for
    // best possible VoIP performance.
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    // Always disable microphone mute during a WebRTC call.
    setMicrophoneMute(false);
    // Set initial device states.
    userSelectedAudioDevice = AudioDevice.NONE;
    selectedAudioDevice = AudioDevice.NONE;
    audioDevices.clear();
    // Initialize and start Bluetooth if a BT device is available or initiate
    // detection of new (enabled) BT devices.
    bluetoothManager.start();
    // Do initial selection of audio device. This setting can later be changed
    // either by adding/removing a BT or wired headset or by covering/uncovering
    // the proximity sensor.
    updateAudioDeviceState();
    // Register receiver for broadcast intents related to adding/removing a
    // wired headset.
    registerReceiver(wiredHeadsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
    Log.d(Config.LOGTAG, "AudioManager started");
}
 
Example 10
Source File: AppRTCAudioManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void start(AudioManagerEvents audioManagerEvents) {
    Log.d(Config.LOGTAG, AppRTCAudioManager.class.getName() + ".start()");
    ThreadUtils.checkIsOnMainThread();
    if (amState == AudioManagerState.RUNNING) {
        Log.e(Config.LOGTAG, "AudioManager is already active");
        return;
    }
    awaitMicrophoneLatch();
    this.audioManagerEvents = audioManagerEvents;
    amState = AudioManagerState.RUNNING;
    // Store current audio state so we can restore it when stop() is called.
    savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn();
    savedIsMicrophoneMute = audioManager.isMicrophoneMute();
    hasWiredHeadset = hasWiredHeadset();
    // Create an AudioManager.OnAudioFocusChangeListener instance.
    audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
        // Called on the listener to notify if the audio focus for this listener has been changed.
        // The |focusChange| value indicates whether the focus was gained, whether the focus was lost,
        // and whether that loss is transient, or whether the new focus holder will hold it for an
        // unknown amount of time.
        // TODO(henrika): possibly extend support of handling audio-focus changes. Only contains
        // logging for now.
        @Override
        public void onAudioFocusChange(int focusChange) {
            final String typeOfChange;
            switch (focusChange) {
                case AudioManager.AUDIOFOCUS_GAIN:
                    typeOfChange = "AUDIOFOCUS_GAIN";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
                    break;
                case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
                    typeOfChange = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS:
                    typeOfChange = "AUDIOFOCUS_LOSS";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
                    typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT";
                    break;
                case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
                    typeOfChange = "AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK";
                    break;
                default:
                    typeOfChange = "AUDIOFOCUS_INVALID";
                    break;
            }
            Log.d(Config.LOGTAG, "onAudioFocusChange: " + typeOfChange);
        }
    };
    // Request audio playout focus (without ducking) and install listener for changes in focus.
    int result = audioManager.requestAudioFocus(audioFocusChangeListener,
            AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        Log.d(Config.LOGTAG, "Audio focus request granted for VOICE_CALL streams");
    } else {
        Log.e(Config.LOGTAG, "Audio focus request failed");
    }
    // Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
    // required to be in this mode when playout and/or recording starts for
    // best possible VoIP performance.
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    // Always disable microphone mute during a WebRTC call.
    setMicrophoneMute(false);
    // Set initial device states.
    userSelectedAudioDevice = AudioDevice.NONE;
    selectedAudioDevice = AudioDevice.NONE;
    audioDevices.clear();
    // Initialize and start Bluetooth if a BT device is available or initiate
    // detection of new (enabled) BT devices.
    bluetoothManager.start();
    // Do initial selection of audio device. This setting can later be changed
    // either by adding/removing a BT or wired headset or by covering/uncovering
    // the proximity sensor.
    updateAudioDeviceState();
    // Register receiver for broadcast intents related to adding/removing a
    // wired headset.
    registerReceiver(wiredHeadsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
    Log.d(Config.LOGTAG, "AudioManager started");
}
 
Example 11
Source File: AvrcpService.java    From Botifier with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void getAudioFocus() {
	if (true || mAudiofocus != AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) {
		setUpRemoteControlClient();
		Log.d(TAG, "Focus acquire " + mAudiofocus);
	}
}
 
Example 12
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;
}