Android MediaRecorder基本使用

使用MediaRecorder实现录音的步骤

①初始化一个新的MediaRecorder的对象,以下所有方法都是该由对象调用的;

②调用setAudioSource()设置音频来源,一般都使用MediaRecorder.AudioSource.MIC;

③使用setOutputFormat()设置输出格式;

④使用setOutputFile()设置输出文件名;

⑤使用setAudioEncoder()设置音频编码器;

⑥调用prepare()使之处于已准备状态;

⑦调用start()开始录音;

⑧调用stop()停止录音;

⑨当使用完MediaRecorder对象后,调用MediaRecorder.release()释放它。

// set record parameter and start recording
try {
    mRecorder = new MediaRecorder();
    mRecorder.setOnErrorListener(this);
    mRecorder.setOnInfoListener(this);
    mRecorder.setAudioSource(MediaRecorder.AudioSource.RADIO_TUNER);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);/*AAC_ADTS*/
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    final int samplingRate = 44100;
    mRecorder.setAudioSamplingRate(samplingRate);
    final int bitRate = 128000;
    mRecorder.setAudioEncodingBitRate(bitRate);
    final int audiochannels = 2;
    mRecorder.setAudioChannels(audiochannels);
    mRecorder.setOutputFile(onGetRecordingFileDescriptor(context));
    mRecorder.prepare();
    mRecordStartTime = SystemClock.elapsedRealtime();
    mRecorder.start();
    setState(STATE_RECORDING);
    mIsRecordingFileSaved = false;
} catch (Exception exception) {
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值