android MediaRecorder使用

MediaRecorder主要用于录制音频和视频的,整个录制过程的状态机如下:

        以下是使用MediaRecorder进行视频录制的一个简单的流程:

MediaRecorder recorder = new MediaRecorder(context);
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
 recorder.setOutputFile(PATH_NAME);
 recorder.prepare();
 recorder.start();   // Recording is now started
 ...
 recorder.stop();
 recorder.reset();   // You can reuse the object by going back to setAudioSource() step
 recorder.release(); // Now the object cannot be reused
 

 MediaRecorder.setOutputFormat(int),设置视频的输出格式,支持一下几种格式:

OutputFormat.DEFAULT,
OutputFormat.THREE_GPP,
OutputFormat.MPEG_4,
OutputFormat.AMR_NB,
OutputFormat.AMR_WB,
OutputFormat.AAC_ADIF,
OutputFormat.AAC_ADTS,
OutputFormat.MPEG_2_TS,
OutputFormat.WEBM,
OutputFormat.HEIF,
OutputFormat.OGG,

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);设置音频的格式,音频格式支持以下几种:

AudioSource.DEFAULT,
AudioSource.MIC,
AudioSource.VOICE_UPLINK,
AudioSource.VOICE_DOWNLINK,
AudioSource.VOICE_CALL,
AudioSource.CAMCORDER,
AudioSource.VOICE_RECOGNITION,
AudioSource.VOICE_COMMUNICATION,
AudioSource.UNPROCESSED,
AudioSource.VOICE_PERFORMANCE,
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264)设置视频编码的格式
VideoEncoder.DEFAULT,
VideoEncoder.H263,
VideoEncoder.H264,
VideoEncoder.MPEG_4_SP,
VideoEncoder.VP8,
VideoEncoder.HEVC,

参考文献:https://developer.android.google.cn/reference/android/media/MediaRecorder?hl=en

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值