Android examples for android.media:Audio
is Match Audio Format
import java.io.IOException; import android.media.MediaExtractor; import android.media.MediaFormat; public class Main { public static boolean isMatchAudioFormat(String audioFile, int sampleRate, int channelCount) { MediaExtractor mex = new MediaExtractor(); try {// w w w. j a v a 2s. co m mex.setDataSource(audioFile); } catch (IOException e) { e.printStackTrace(); } MediaFormat mf = mex.getTrackFormat(0); boolean result = true; if (sampleRate != -1) { result = sampleRate == mf.getInteger(MediaFormat.KEY_SAMPLE_RATE); } if (result && channelCount != -1) { result = channelCount == mf.getInteger(MediaFormat.KEY_CHANNEL_COUNT); } mex.release(); return result; } }