Java Code Examples for android.media.AudioManager#registerAudioDeviceCallback()

The following examples show how to use android.media.AudioManager#registerAudioDeviceCallback() . 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: MediaPlayer.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void registerAudioPlugV23(boolean register) {
    AudioManager am = (AudioManager) mLibVLC.mAppContext.getSystemService(Context.AUDIO_SERVICE);
    if (register) {
        mAudioDeviceCallback.onAudioDevicesAdded(am.getDevices(AudioManager.GET_DEVICES_OUTPUTS));
        am.registerAudioDeviceCallback(mAudioDeviceCallback, null);
    } else {
        am.unregisterAudioDeviceCallback(mAudioDeviceCallback);
    }
}
 
Example 2
Source File: MediaPlayer.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void registerAudioPlugV23(boolean register) {
    AudioManager am = (AudioManager) mLibVLC.mAppContext.getSystemService(Context.AUDIO_SERVICE);
    if (register) {
        mAudioDeviceCallback.onAudioDevicesAdded(am.getDevices(AudioManager.GET_DEVICES_OUTPUTS));
        am.registerAudioDeviceCallback(mAudioDeviceCallback, null);
    } else {
        am.unregisterAudioDeviceCallback(mAudioDeviceCallback);
    }
}
 
Example 3
Source File: MediaPlayer.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void registerAudioPlugV23(boolean register) {
    AudioManager am = (AudioManager) mLibVLC.mAppContext.getSystemService(Context.AUDIO_SERVICE);
    if (register) {
        mAudioDeviceCallback.onAudioDevicesAdded(am.getDevices(AudioManager.GET_DEVICES_OUTPUTS));
        am.registerAudioDeviceCallback(mAudioDeviceCallback, null);
    } else {
        am.unregisterAudioDeviceCallback(mAudioDeviceCallback);
    }
}
 
Example 4
Source File: MediaPlayer.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void registerAudioPlugV23(boolean register) {
    AudioManager am = (AudioManager) mLibVLC.mAppContext.getSystemService(Context.AUDIO_SERVICE);
    if (register) {
        mAudioDeviceCallback.onAudioDevicesAdded(am.getDevices(AudioManager.GET_DEVICES_OUTPUTS));
        am.registerAudioDeviceCallback(mAudioDeviceCallback, null);
    } else {
        am.unregisterAudioDeviceCallback(mAudioDeviceCallback);
    }
}
 
Example 5
Source File: MediaPlayer.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void registerAudioPlugV23(boolean register) {
    AudioManager am = (AudioManager) mLibVLC.mAppContext.getSystemService(Context.AUDIO_SERVICE);
    if (register) {
        mAudioDeviceCallback.onAudioDevicesAdded(am.getDevices(AudioManager.GET_DEVICES_OUTPUTS));
        am.registerAudioDeviceCallback(mAudioDeviceCallback, null);
    } else {
        am.unregisterAudioDeviceCallback(mAudioDeviceCallback);
    }
}
 
Example 6
Source File: HeadphoneStateMonitor.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Initializes this HeadphoneStateMonitor to start listening to headphone state changes. */
public void startMonitoring() {
  AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
  // Initialize the active device count.
  mConnectedAudioDevices.clear();
  AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
  for (AudioDeviceInfo device : devices) {
    if (isExternalDevice(device)) {
      mConnectedAudioDevices.add(device.getId());
    }
  }
  audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, /* use the main thread */ null);
}