Get a valid sample Audio rate for the device - Android Media

Android examples for Media:Audio

Description

Get a valid sample Audio rate for the device

Demo Code


//package com.java2s;
import android.media.AudioRecord;

public class Main {
    /**/*from   ww w . j  a v  a 2s. com*/
     * 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