Vla*_*kin 2 video android record
我的代码:
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
CamcorderProfile profile = CamcorderProfile.get(QUALITY_LOW);
mediaRecorder.setProfile(profile);
Run Code Online (Sandbox Code Playgroud)
有用.但我只需要录制视频.
如果我不使用mediaRecorder.setAudioSource(),则mediaRecorder.setProfile()会因IllegalStateException而失败.
任何的想法?
public void setProfile(CamcorderProfile profile)
从以下版本开始:API Level 8使用CamcorderProfile对象中的设置进行录制.应在设置视频和音频源之后以及setOutputFile()之前调用此方法.
来自Android - CamcorderProfile文档
每个配置文件指定以下参数集:
- 文件输出格式
- 视频编解码器格式
- 视频比特率,以每秒位数为单位
- 视频帧速率,以每秒帧数为单位
- 视频帧宽和高度,
- 音频编解码器格式音频比特率,以每秒位数为单位
- 音频采样率
- 录制的音频通道数.
我想你可以从所需的CamcorderProfile中读取相关的视频相关设置,并自己明确设置它们.
小智 5
MediaRecorder 的 setProfile() 方法

我们可以看到,如果:
profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW //1002
&&
profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA //1007
Run Code Online (Sandbox Code Playgroud)
不会有 setAudio*() 所以在你的代码中你可以手动设置profile.quality=[any int from 1002 to 1007]之前setProfile()。它会起作用,我试过了。
我找到了正确的答案:
if (getIsMuteShooting()) { // with out audio
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setVideoEncoder(profile.videoCodec);
} else {
mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setAudioEncodingBitRate(profile.audioBitRate);
mRecorder.setAudioChannels(profile.audioChannels);
mRecorder.setAudioSamplingRate(profile.audioSampleRate);
mRecorder.setVideoEncoder(profile.videoCodec);
mRecorder.setAudioEncoder(profile.audioCodec);
}
Run Code Online (Sandbox Code Playgroud)