首页 > 学院 > 开发设计 > 正文

andriod显示录制视频的简单dome

2019-11-08 00:25:00
字体:
来源:转载
供稿:网友

话不多说,上步骤

(1)获取SurfaceView的id

SurfaceView main_sfv = (SurfaceView) findViewById(R.id.mian_sfv);

(2)实例化媒体录制器

MediaRecorder mediaRecorder = new MediaRecorder();(3)button跳进方法,执行如下dome

mediaRecorder.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" />


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表