Get a valid sample rate for the device - Android android.media

Android examples for android.media:AudioRecord

Description

Get a valid sample rate for the device

Demo Code

import android.media.AudioRecord;

public class Main {

  /**//from  w  w w  .  ja  va2 s  .co m
   * Get a valid sample rate for the device
   *
   * @param channelConfiguration
   *          the channel configuration
   * @param audioEncoding
   *          the audio encoding
   * @return the valid sample rates
   */
  public static int getValidSampleRates(int channelConfiguration, int audioEncoding) {
    for (int rate : new int[] { 8000, 11025, 16000, 22050, 44100 }) { // add the rates you wish to check against
      int bffrSize = AudioRecord.getMinBufferSize(rate, channelConfiguration, audioEncoding);
      if (bffrSize > 0) {
        return bffrSize;
      }
    }
    return 0;
  }

}

Related Tutorials