Java Code Examples for android.media.AudioDeviceInfo#getEncodings()

The following examples show how to use android.media.AudioDeviceInfo#getEncodings() . 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: 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 2
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 3
Source File: AudioDeviceInfoConverter.java    From vinyl-cast with MIT License 4 votes vote down vote up
/**
 * Converts an {@link AudioDeviceInfo} object into a human readable representation
 *
 * @param adi The AudioDeviceInfo object to be converted to a String
 * @return String containing all the information from the AudioDeviceInfo object
 */
static String toString(AudioDeviceInfo adi){

    StringBuilder sb = new StringBuilder();
    sb.append("Id: ");
    sb.append(adi.getId());

    sb.append("\nProduct name: ");
    sb.append(adi.getProductName());

    sb.append("\nType: ");
    sb.append(typeToString(adi.getType()));

    sb.append("\nIs source: ");
    sb.append((adi.isSource() ? "Yes" : "No"));

    sb.append("\nIs sink: ");
    sb.append((adi.isSink() ? "Yes" : "No"));

    sb.append("\nChannel counts: ");
    int[] channelCounts = adi.getChannelCounts();
    sb.append(intArrayToString(channelCounts));

    sb.append("\nChannel masks: ");
    int[] channelMasks = adi.getChannelMasks();
    sb.append(intArrayToString(channelMasks));

    sb.append("\nChannel index masks: ");
    int[] channelIndexMasks = adi.getChannelIndexMasks();
    sb.append(intArrayToString(channelIndexMasks));

    sb.append("\nEncodings: ");
    int[] encodings = adi.getEncodings();
    sb.append(intArrayToString(encodings));

    sb.append("\nSample Rates: ");
    int[] sampleRates = adi.getSampleRates();
    sb.append(intArrayToString(sampleRates));

    return sb.toString();
}