Java Code Examples for android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
The following examples show how to use
android.media.AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE .
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 |
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: FocusRequester.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * 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 3
Source File: FlutterIncallManagerPlugin.java From flutter-incall-manager with ISC License | 5 votes |
@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 4
Source File: InCallManagerModule.java From react-native-incall-manager with ISC License | 5 votes |
@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 5
Source File: AppRTCAudioManager.java From imsdk-android with MIT License | 4 votes |
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 6
Source File: AppRTCAudioManager.java From Pix-Art-Messenger with GNU General Public License v3.0 | 4 votes |
@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 7
Source File: AppRTCAudioManager.java From Conversations with GNU General Public License v3.0 | 4 votes |
@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 8
Source File: VideoView.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * 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; }