android.media.AudioDeviceInfo Java Examples

The following examples show how to use android.media.AudioDeviceInfo. 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: 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 #2
Source File: AudioDeviceListEntry.java    From vinyl-cast with MIT License 6 votes vote down vote up
@TargetApi(23)
static List<AudioDeviceListEntry> createFilteredListFrom(AudioDeviceInfo[] devices, int directionType, Set<Integer> filteredTypes){

    List<AudioDeviceListEntry> listEntries = new Vector<>();
    for (AudioDeviceInfo info : devices) {
        if (directionType == AudioManager.GET_DEVICES_ALL ||
                (directionType == AudioManager.GET_DEVICES_OUTPUTS && info.isSink()) ||
                (directionType == AudioManager.GET_DEVICES_INPUTS && info.isSource())) {
            if (filteredTypes.contains(info.getType())) {
                continue;
            }
            listEntries.add(new AudioDeviceListEntry(info.getId(), info.getType(),
                    info.getProductName() + ": " + AudioDeviceInfoConverter.typeToString(info.getType())));
        }
    }
    return listEntries;
}
 
Example #3
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 #4
Source File: HeadsetTracker.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
HeadsetTracker(Context context, HeadsetUSourceData data,
               @NonNull PendingIntent event_positive,
               @NonNull PendingIntent event_negative) {
    super(context, data, event_positive, event_negative);

    boolean plugged_in = false;
    Boolean has_microphone = null;

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        AudioDeviceInfo[] audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo deviceInfo : audioDevices) {
            if (deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
                    || deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                plugged_in = true;
                has_microphone = deviceInfo.isSource();
            }
        }
    } else {
        plugged_in = audioManager.isWiredHeadsetOn();
    }
    Boolean match = determine_match(data, plugged_in, has_microphone);
    newSatisfiedState(match);
}
 
Example #5
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 #6
Source File: MediaStreamingStatus.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressLint("MissingPermission")
public synchronized boolean isAudioOutputAvailable() {
    Context context = contextWeakReference.get();
    if(context == null){ return false;}

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    // If API level 23+ audio manager can iterate over all current devices to see if a supported
    // device is present.
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
        AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        if(deviceInfos != null) {
            for (AudioDeviceInfo deviceInfo : deviceInfos) {
                if (deviceInfo != null && isSupportedAudioDevice(deviceInfo.getType())) {
                    return true;
                }
            }
        }
        return false;
    }

    //This means the SDK version is < M, and our min is 8 so this API is always available
    return audioManager.isBluetoothA2dpOn();
}
 
Example #7
Source File: MediaStreamingStatusTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testEmptyAudioDeviceInfoList(){
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        assertNotNull(mockedContext);
        MediaStreamingStatus mediaStreamingStatus = new MediaStreamingStatus(mockedContext, new MediaStreamingStatus.Callback() {
            @Override
            public void onAudioNoLongerAvailable() {

            }
        });
        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return new AudioDeviceInfo[0];
            }
        }).when(audioManager).getDevices(AudioManager.GET_DEVICES_OUTPUTS);


        assertFalse(mediaStreamingStatus.isAudioOutputAvailable());
    }
}
 
Example #8
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 #9
Source File: MainActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the wear device has a built-in speaker and if it is supported. Speaker, even if
 * physically present, is only supported in Android M+ on a wear device..
 */
public final boolean speakerIsSupported() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PackageManager packageManager = getPackageManager();
        // The results from AudioManager.getDevices can't be trusted unless the device
        // advertises FEATURE_AUDIO_OUTPUT.
        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
            return false;
        }
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        for (AudioDeviceInfo device : devices) {
            if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                return true;
            }
        }
    }
    return false;
}
 
Example #10
Source File: MediaStreamingStatusTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testAcceptedUSBDevices(){
    MediaStreamingStatus mediaStreamingStatus = spy(new MediaStreamingStatus(getContext(), mock(MediaStreamingStatus.Callback.class)));

    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    }).when(mediaStreamingStatus).isUsbActuallyConnected();

    assertTrue(mediaStreamingStatus.isUsbActuallyConnected());
    assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_DEVICE));
    assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_ACCESSORY));
    assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_USB_HEADSET));
    assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_DOCK));
}
 
Example #11
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 #12
Source File: MediaStreamingStatusTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testAcceptedLineDevices(){
    assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_LINE_ANALOG));
    assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_LINE_DIGITAL));
    assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_AUX_LINE));
    assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADSET));
    assertTrue(defaultMediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADPHONES));
}
 
Example #13
Source File: HeadphoneStateMonitor.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static boolean isExternalDevice(AudioDeviceInfo device) {
  return device.isSink()
      && (device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP
          || device.getType() == AudioDeviceInfo.TYPE_AUX_LINE
          || device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
          || device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET
          || device.getType() == AudioDeviceInfo.TYPE_USB_HEADSET);
}
 
Example #14
Source File: HeadphoneStateMonitor.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Whether the device is currently connected to bluetooth or wired headphones for audio output.
 * When called on older devices this use a deprecat methods on audioManager to get the same
 * result.
 */
@SuppressWarnings("deprecation")
public static boolean isHeadphoneOn(Context context) {
  AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
  for (AudioDeviceInfo device : devices) {
    if (isExternalDevice(device)) {
      // While there can be more than one external audio device, finding one is enough here.
      return true;
    }
  }
  return false;
}
 
Example #15
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);
}
 
Example #16
Source File: MediaStreamingStatusTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testAcceptedBTDevices(){
    MediaStreamingStatus mediaStreamingStatus = spy(new MediaStreamingStatus(getContext(), mock(MediaStreamingStatus.Callback.class)));

    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    }).when(mediaStreamingStatus).isBluetoothActuallyAvailable();

    assertTrue(mediaStreamingStatus.isBluetoothActuallyAvailable());
    assertTrue(mediaStreamingStatus.isSupportedAudioDevice(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP));
}
 
Example #17
Source File: AssistantActivity.java    From sample-googleassistant with Apache License 2.0 5 votes vote down vote up
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
    AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
    for (AudioDeviceInfo adi : adis) {
        if (adi.getType() == deviceType) {
            return adi;
        }
    }
    return null;
}
 
Example #18
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 5 votes vote down vote up
private static void logAudioDeviceInfo(String tag, AudioManager audioManager) {
  if (Build.VERSION.SDK_INT < 23) {
    return;
  }
  final AudioDeviceInfo[] devices =
      audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
  if (devices.length == 0) {
    return;
  }
  Logging.d(tag, "Audio Devices: ");
  for (AudioDeviceInfo device : devices) {
    StringBuilder info = new StringBuilder();
    info.append("  ").append(deviceTypeToString(device.getType()));
    info.append(device.isSource() ? "(in): " : "(out): ");
    // An empty array indicates that the device supports arbitrary channel counts.
    if (device.getChannelCounts().length > 0) {
      info.append("channels=").append(Arrays.toString(device.getChannelCounts()));
      info.append(", ");
    }
    if (device.getEncodings().length > 0) {
      // Examples: ENCODING_PCM_16BIT = 2, ENCODING_PCM_FLOAT = 4.
      info.append("encodings=").append(Arrays.toString(device.getEncodings()));
      info.append(", ");
    }
    if (device.getSampleRates().length > 0) {
      info.append("sample rates=").append(Arrays.toString(device.getSampleRates()));
      info.append(", ");
    }
    info.append("id=").append(device.getId());
    Logging.d(tag, info.toString());
  }
}
 
Example #19
Source File: AudioDeviceListEntry.java    From vinyl-cast with MIT License 5 votes vote down vote up
/**
 * Create a list of AudioDeviceListEntry objects from a list of AudioDeviceInfo objects.
 *
 * @param devices A list of {@Link AudioDeviceInfo} objects
 * @param directionType Only audio devices with this direction will be included in the list.
 *                      Valid values are GET_DEVICES_ALL, GET_DEVICES_OUTPUTS and
 *                      GET_DEVICES_INPUTS.
 * @return A list of AudioDeviceListEntry objects
 */
@TargetApi(23)
static List<AudioDeviceListEntry> createListFrom(AudioDeviceInfo[] devices, int directionType){

    List<AudioDeviceListEntry> listEntries = new Vector<>();
    for (AudioDeviceInfo info : devices) {
        if (directionType == AudioManager.GET_DEVICES_ALL ||
                (directionType == AudioManager.GET_DEVICES_OUTPUTS && info.isSink()) ||
                (directionType == AudioManager.GET_DEVICES_INPUTS && info.isSource())) {
            listEntries.add(new AudioDeviceListEntry(info.getId(), info.getType(),
                    info.getProductName() + " " + AudioDeviceInfoConverter.typeToString(info.getType())));
        }
    }
    return listEntries;
}
 
Example #20
Source File: AudioDeviceSpinner.java    From vinyl-cast with MIT License 5 votes vote down vote up
@TargetApi(23)
public void setDirectionType(int directionType){
    this.mDirectionType = directionType;

    if (directionType == AudioManager.GET_DEVICES_OUTPUTS) {
        // Add a default entry to the list and select it
        mDeviceAdapter.insert(new AudioDeviceListEntry(AudioRecordStreamProvider.AUDIO_DEVICE_ID_NONE, AudioDeviceInfo.TYPE_UNKNOWN,
                mContext.getString(R.string.audio_device_none)), 0);
        setSelection(0);
    }

    setupAudioDeviceCallback();
}
 
Example #21
Source File: AudioDeviceSpinner.java    From vinyl-cast with MIT License 5 votes vote down vote up
private void setup(Context context){
    mContext = context;
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    mDeviceAdapter = new AudioDeviceAdapter(context);
    setAdapter(mDeviceAdapter);

    // Add a default entry to the list and select it
    mDeviceAdapter.add(new AudioDeviceListEntry(AudioRecordStreamProvider.AUDIO_DEVICE_ID_AUTO_SELECT, AudioDeviceInfo.TYPE_UNKNOWN,
            context.getString(R.string.audio_device_auto_select)));
    setSelection(0);
}
 
Example #22
Source File: AudioDevicePreference.java    From vinyl-cast with MIT License 5 votes vote down vote up
@TargetApi(23)
public void setDirectionType(int directionType){
    this.mDirectionType = directionType;

    if (directionType == AudioManager.GET_DEVICES_OUTPUTS) {
        // Add an entry for NONE to the list
        mDeviceAdapter.insert(new AudioDeviceListEntry(AudioRecordStreamProvider.AUDIO_DEVICE_ID_NONE, AudioDeviceInfo.TYPE_UNKNOWN,
                mContext.getString(R.string.audio_device_none)), 0);
    }

    setupAudioDeviceCallback();
}
 
Example #23
Source File: AudioDevicePreference.java    From vinyl-cast with MIT License 5 votes vote down vote up
public AudioDevicePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mContext = context;
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mDeviceAdapter = createAdapter(mContext);

    // Add a default entry to the list
    mDeviceAdapter.add(new AudioDeviceListEntry(AudioRecordStreamProvider.AUDIO_DEVICE_ID_AUTO_SELECT, AudioDeviceInfo.TYPE_UNKNOWN,
            context.getString(R.string.audio_device_auto_select)));
}
 
Example #24
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
    AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
    for (AudioDeviceInfo adi : adis) {
        if (adi.getType() == deviceType) {
            return adi;
        }
    }
    return null;
}
 
Example #25
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
    AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
    for (AudioDeviceInfo adi : adis) {
        if (adi.getType() == deviceType) {
            return adi;
        }
    }
    return null;
}
 
Example #26
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
    AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
    for (AudioDeviceInfo adi : adis) {
        if (adi.getType() == deviceType) {
            return adi;
        }
    }
    return null;
}
 
Example #27
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
    AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
    for (AudioDeviceInfo adi : adis) {
        if (adi.getType() == deviceType) {
            return adi;
        }
    }
    return null;
}
 
Example #28
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 5 votes vote down vote up
private static void logAudioDeviceInfo(String tag, AudioManager audioManager) {
  if (Build.VERSION.SDK_INT < 23) {
    return;
  }
  final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
  if (devices.length == 0) {
    return;
  }
  Logging.d(tag, "Audio Devices: ");
  for (AudioDeviceInfo device : devices) {
    StringBuilder info = new StringBuilder();
    info.append("  ").append(deviceTypeToString(device.getType()));
    info.append(device.isSource() ? "(in): " : "(out): ");
    // An empty array indicates that the device supports arbitrary channel counts.
    if (device.getChannelCounts().length > 0) {
      info.append("channels=").append(Arrays.toString(device.getChannelCounts()));
      info.append(", ");
    }
    if (device.getEncodings().length > 0) {
      // Examples: ENCODING_PCM_16BIT = 2, ENCODING_PCM_FLOAT = 4.
      info.append("encodings=").append(Arrays.toString(device.getEncodings()));
      info.append(", ");
    }
    if (device.getSampleRates().length > 0) {
      info.append("sample rates=").append(Arrays.toString(device.getSampleRates()));
      info.append(", ");
    }
    info.append("id=").append(device.getId());
    Logging.d(tag, info.toString());
  }
}
 
Example #29
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 #30
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 "";
    }
}