create Audio Record - Android Media

Android examples for Media:Audio

Description

create Audio Record

Demo Code


//package com.java2s;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

public class Main {
    private static int audioSource = MediaRecorder.AudioSource.MIC;
    private static int sampleRateInHz = 16000;
    private static int channelConfig = AudioFormat.CHANNEL_IN_MONO;
    private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    private static int bufferSizeInBytes = 0;
    private static AudioRecord audioRecord;

    private static void creatAudioRecord() {
        audioRecord = null;//from   w  ww .  j  a va2 s  .  co m
        // ??????
        bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,
                channelConfig, audioFormat);
        // ????AudioRecord????
        audioRecord = new AudioRecord(audioSource, sampleRateInHz,
                channelConfig, audioFormat, bufferSizeInBytes);
    }
}

Related Tutorials