Java Code Examples for android.media.AudioDeviceInfo#TYPE_USB_DEVICE

The following examples show how to use android.media.AudioDeviceInfo#TYPE_USB_DEVICE . 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: FlutterIncallManagerPlugin.java    From flutter-incall-manager with ISC License 6 votes vote down vote up
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(TAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(TAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 2
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(TAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(TAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 3
Source File: AppRTCAudioManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 4
Source File: AppRTCAudioManager.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 5
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 5 votes vote down vote up
private static String deviceTypeToString(int type) {
  switch (type) {
    case AudioDeviceInfo.TYPE_UNKNOWN:
      return "TYPE_UNKNOWN";
    case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
      return "TYPE_BUILTIN_EARPIECE";
    case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
      return "TYPE_BUILTIN_SPEAKER";
    case AudioDeviceInfo.TYPE_WIRED_HEADSET:
      return "TYPE_WIRED_HEADSET";
    case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
      return "TYPE_WIRED_HEADPHONES";
    case AudioDeviceInfo.TYPE_LINE_ANALOG:
      return "TYPE_LINE_ANALOG";
    case AudioDeviceInfo.TYPE_LINE_DIGITAL:
      return "TYPE_LINE_DIGITAL";
    case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
      return "TYPE_BLUETOOTH_SCO";
    case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
      return "TYPE_BLUETOOTH_A2DP";
    case AudioDeviceInfo.TYPE_HDMI:
      return "TYPE_HDMI";
    case AudioDeviceInfo.TYPE_HDMI_ARC:
      return "TYPE_HDMI_ARC";
    case AudioDeviceInfo.TYPE_USB_DEVICE:
      return "TYPE_USB_DEVICE";
    case AudioDeviceInfo.TYPE_USB_ACCESSORY:
      return "TYPE_USB_ACCESSORY";
    case AudioDeviceInfo.TYPE_DOCK:
      return "TYPE_DOCK";
    case AudioDeviceInfo.TYPE_FM:
      return "TYPE_FM";
    case AudioDeviceInfo.TYPE_BUILTIN_MIC:
      return "TYPE_BUILTIN_MIC";
    case AudioDeviceInfo.TYPE_FM_TUNER:
      return "TYPE_FM_TUNER";
    case AudioDeviceInfo.TYPE_TV_TUNER:
      return "TYPE_TV_TUNER";
    case AudioDeviceInfo.TYPE_TELEPHONY:
      return "TYPE_TELEPHONY";
    case AudioDeviceInfo.TYPE_AUX_LINE:
      return "TYPE_AUX_LINE";
    case AudioDeviceInfo.TYPE_IP:
      return "TYPE_IP";
    case AudioDeviceInfo.TYPE_BUS:
      return "TYPE_BUS";
    case AudioDeviceInfo.TYPE_USB_HEADSET:
      return "TYPE_USB_HEADSET";
    default:
      return "TYPE_UNKNOWN";
  }
}
 
Example 6
Source File: MediaStreamingStatus.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method will check to ensure that the device is supported. If possible, it will also
 * check against known variables and flags to ensure that that device is connected. This is
 * required as the AudioManager tends to be untrustworthy.
 * @param audioDevice
 * @return
 */
boolean isSupportedAudioDevice(int audioDevice){
    DebugTool.logInfo("Audio device connected: " + audioDevice);
    switch (audioDevice){
        case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
          if(isBluetoothActuallyAvailable()) {
              setupBluetoothBroadcastReceiver();
              return true; //Make sure this doesn't fall to any other logic after this point
          }
          return false;
        case AudioDeviceInfo.TYPE_DOCK:
        case AudioDeviceInfo.TYPE_USB_ACCESSORY:
        case AudioDeviceInfo.TYPE_USB_DEVICE:
        case AudioDeviceInfo.TYPE_USB_HEADSET:
            if(isUsbActuallyConnected()) {
                setupUSBBroadcastReceiver();
                return true;
            }
            return false;
        case AudioDeviceInfo.TYPE_LINE_ANALOG:
        case AudioDeviceInfo.TYPE_LINE_DIGITAL:
        case AudioDeviceInfo.TYPE_WIRED_HEADSET:
        case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
        case AudioDeviceInfo.TYPE_AUX_LINE:
            setupHeadsetBroadcastReceiver();
            return true;
    }
    return false;
}
 
Example 7
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 4 votes vote down vote up
private static String deviceTypeToString(int type) {
  switch (type) {
    case AudioDeviceInfo.TYPE_UNKNOWN:
      return "TYPE_UNKNOWN";
    case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
      return "TYPE_BUILTIN_EARPIECE";
    case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
      return "TYPE_BUILTIN_SPEAKER";
    case AudioDeviceInfo.TYPE_WIRED_HEADSET:
      return "TYPE_WIRED_HEADSET";
    case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
      return "TYPE_WIRED_HEADPHONES";
    case AudioDeviceInfo.TYPE_LINE_ANALOG:
      return "TYPE_LINE_ANALOG";
    case AudioDeviceInfo.TYPE_LINE_DIGITAL:
      return "TYPE_LINE_DIGITAL";
    case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
      return "TYPE_BLUETOOTH_SCO";
    case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
      return "TYPE_BLUETOOTH_A2DP";
    case AudioDeviceInfo.TYPE_HDMI:
      return "TYPE_HDMI";
    case AudioDeviceInfo.TYPE_HDMI_ARC:
      return "TYPE_HDMI_ARC";
    case AudioDeviceInfo.TYPE_USB_DEVICE:
      return "TYPE_USB_DEVICE";
    case AudioDeviceInfo.TYPE_USB_ACCESSORY:
      return "TYPE_USB_ACCESSORY";
    case AudioDeviceInfo.TYPE_DOCK:
      return "TYPE_DOCK";
    case AudioDeviceInfo.TYPE_FM:
      return "TYPE_FM";
    case AudioDeviceInfo.TYPE_BUILTIN_MIC:
      return "TYPE_BUILTIN_MIC";
    case AudioDeviceInfo.TYPE_FM_TUNER:
      return "TYPE_FM_TUNER";
    case AudioDeviceInfo.TYPE_TV_TUNER:
      return "TYPE_TV_TUNER";
    case AudioDeviceInfo.TYPE_TELEPHONY:
      return "TYPE_TELEPHONY";
    case AudioDeviceInfo.TYPE_AUX_LINE:
      return "TYPE_AUX_LINE";
    case AudioDeviceInfo.TYPE_IP:
      return "TYPE_IP";
    case AudioDeviceInfo.TYPE_BUS:
      return "TYPE_BUS";
    case AudioDeviceInfo.TYPE_USB_HEADSET:
      return "TYPE_USB_HEADSET";
    default:
      return "TYPE_UNKNOWN";
  }
}
 
Example 8
Source File: AudioDeviceInfoConverter.java    From vinyl-cast with MIT License 4 votes vote down vote up
/**
 * Converts the value from {@link AudioDeviceInfo#getType()} into a human
 * readable string
 * @param type One of the {@link AudioDeviceInfo}.TYPE_* values
 *             e.g. AudioDeviceInfo.TYPE_BUILT_IN_SPEAKER
 * @return string which describes the type of audio device
 */
static String typeToString(int type){
    switch (type) {
        case AudioDeviceInfo.TYPE_AUX_LINE:
            return "aux line-level connectors";
        case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
            return "Bluetooth device w/ A2DP profile";
        case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
            return "Bluetooth device w/ telephony";
        case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
            return "built-in earphone speaker";
        case AudioDeviceInfo.TYPE_BUILTIN_MIC:
            return "built-in microphone";
        case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
            return "built-in speaker";
        case AudioDeviceInfo.TYPE_BUS:
            return "BUS";
        case AudioDeviceInfo.TYPE_DOCK:
            return "DOCK";
        case AudioDeviceInfo.TYPE_FM:
            return "FM";
        case AudioDeviceInfo.TYPE_FM_TUNER:
            return "FM tuner";
        case AudioDeviceInfo.TYPE_HDMI:
            return "HDMI";
        case AudioDeviceInfo.TYPE_HDMI_ARC:
            return "HDMI audio return channel";
        case AudioDeviceInfo.TYPE_IP:
            return "IP";
        case AudioDeviceInfo.TYPE_LINE_ANALOG:
            return "line analog";
        case AudioDeviceInfo.TYPE_LINE_DIGITAL:
            return "line digital";
        case AudioDeviceInfo.TYPE_TELEPHONY:
            return "telephony";
        case AudioDeviceInfo.TYPE_TV_TUNER:
            return "TV tuner";
        case AudioDeviceInfo.TYPE_USB_ACCESSORY:
            return "USB accessory";
        case AudioDeviceInfo.TYPE_USB_DEVICE:
            return "USB device";
        case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
            return "wired headphones";
        case AudioDeviceInfo.TYPE_WIRED_HEADSET:
            return "wired headset";
        default:
        case AudioDeviceInfo.TYPE_UNKNOWN:
            return "";
    }
}