话不多说,上步骤
(1)获取SurfaceView的id
SurfaceView main_sfv = (SurfaceView) findViewById(R.id.mian_sfv);(2)实例化媒体录制器
MediaRecorder mediaRecorder = new MediaRecorder();(3)button跳进方法,执行如下domemediaRecorder.reset();mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);mediaRecorder.setVideoEncodingBitRate(3);//设置保存的路径mediaRecorder.setOutputFile("mnt/sdcard/G150825_"+System.currentTimeMillis()+".mp4");//将画面展示到SurfaceViewmediaRecorder.setPReviewDisplay(main_sfv.getHolder().getSurface());try { mediaRecorder.prepare(); mediaRecorder.start();} catch (IOException e) { e.printStackTrace();}(注意权限)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
新闻热点
疑难解答