最近在使用MediaRecorder录制视频的时候遇到crash
2016-07-28 10:09
453 查看
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //设置视频源 recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); //recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P)); //设置输出格式 recorder.setOutputFormat(OUTPUT_FORMAT); recorder.setAudioEncoder(AUDIO_ENCODER); //设置视频编码 recorder.setVideoEncoder(VIDEO_ENCODER); // 设置视频录制的分辨率。必须放在设置编码和格式的后面,否则报错 recorder.setVideoSize(width, height); // 设置录制的视频帧率。必须放在设置编码和格式的后面,否则报错 recorder.setVideoFrameRate(frameRate); recorder.setOrientationHint(90); recorder.setPreviewDisplay(surfaceHolder.getSurface()); recorder.setOutputFile("/sdcard/v.mp4"); //disable this limit recorder.setMaxDuration(0); recorder.setMaxFileSize(0); recorder.setOnErrorListener(this); recorder.setOnInfoListener(this);
在没有setProfile的时候能正常工作,但是视频质量不行,
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P));于是报出
setOutputFormat called in an invalid state
后来在stackoverflow找到答案
http://stackoverflow.com/questions/21632769/setoutputformat-called-in-an-invalid-state-4-where-and-why
public void setProfile(CamcorderProfile profile) { setOutputFormat(profile.fileFormat); setVideoFrameRate(profile.videoFrameRate); setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); setVideoEncodingBitRate(profile.videoBitRate); setVideoEncoder(profile.videoCodec); if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW && profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) { // Nothing needs to be done. Call to setCaptureRate() enables // time lapse video recording. } else { setAudioEncodingBitRate(profile.audioBitRate); setAudioChannels(profile.audioChannels); setAudioSamplingRate(profile.audioSampleRate); setAudioEncoder(profile.audioCodec); } }
原来在setProfile里面把这些事情都做了,不需要再重复做
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories