使用x5cloud云平台来做网络彩讯-------------录制视频方案(三)
在录制视频上,有很大的选择余地,像调用本地的录制程序或者自己写,调用本地的就不多说了,下面说说MediaRecorder的使用
????MediaRecorder ?myRecorder = new MediaRecorder();
myFile = File.createTempFile("myfile", ".3gp",Environment.getExternalStorageDirectory());// 使camera先处于停止状态stopRecord();isRecord = true;// 为了快速在预览和录制之间转换,故使用此函数// recorder.setCamera()一般于recorder.setVideoSource()之前调用,否则会有异常myRecorder.setCamera(camera);// 设置视频源为cameramyRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);// 设置音频源为micmyRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);// 设置输出文件的格式为3gpmyRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);//recorder.setAudioChannels(2);// 最长录制5000秒钟myRecorder.setMaxDuration(sec);// 最大录制500MmyRecorder.setMaxFileSize(500000000);// 512k/smyRecorder.setVideoEncodingBitRate(EncodingBitRate);//帧数myRecorder.setVideoFrameRate(videoFrameRate);// recorder.setAudioSamplingRate(12);// recorder.setAudioEncodingBitRate(1200);// 设置音频编码myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);// 设置视频编码myRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// 设置录制视频的分辨率myRecorder.setVideoSize(240, 120);// 输出文件的路径和名称myRecorder.setOutputFile(myFile.getAbsolutePath());myRecorder.setPreviewDisplay(mySurfaceHolder.getSurface());// 准备,开始,视频录制myRecorder.prepare();myRecorder.start();
?stopRecord();
if (isRecord){// 设置myRecorder为空的状态,为下次录制做准备myRecorder.reset();}
?camera.stopPreview();?camera.release();?camera = null;
?