找传奇、传世资源到传世资源站!

android视频拍摄 实例源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

android视频拍摄 实例源码下载 Android平台开发-第1张package com.xushouwei.videorecoder;import java.io.File;import java.io.IOException;import android.app.Activity;import android.media.MediaRecorder;import android.os.Bundle;import android.os.Environment;import android.view.MotionEvent;import android.view.SurfaceHolder;import android.view.SurfaceView;import android.view.View;import android.view.ViewGroup;import android.view.Window;import android.view.WindowManager;import android.widget.Button;import android.widget.RelativeLayout;public class MainActivity extends Activity {/** Called when the activity is first created. */private SurfaceView surfaceView;private RelativeLayout layout;private Button recorderbutton;private Button stopbutton;private MediaRecorder mediaRecorder;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 设置窗口无标题requestWindowFeature(Window.FEATURE_NO_TITLE);// 设置窗口全屏getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.main);// 找到SurfaceView显示控件surfaceView = (SurfaceView) this.findViewById(R.id.surfaceView);// 设置参数//直接输送到屏幕前段surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);// 设置分辨率surfaceView.getHolder().setFixedSize(176, 144);// 要求不要锁屏surfaceView.getHolder().setKeepScreenOn(true);// 找到相对布局显示控件layout = (RelativeLayout) this.findViewById(R.id.layout);recorderbutton = (Button) this.findViewById(R.id.recorderbutton);stopbutton = (Button) this.findViewById(R.id.stopbutton);}public void record(View v) {switch (v.getId()) {case R.id.recorderbutton:try {File videoFile = new File(Environment.getExternalStorageDirectory(),System.currentTimeMillis() ".3gp");// 媒体刻录类mediaRecorder = new MediaRecorder();// 设置媒体声音来源为麦克风mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);// 设置媒体视频来源为摄像头mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);// 设置输出格式mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);// 设置视频大小mediaRecorder.setVideoSize(320, 240);// 设置每秒捕获画面的帧数mediaRecorder.setVideoFrameRate(5);// 设置视频声音编码格式mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);// 设置视频编码mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// 设置文件输出位置mediaRecorder.setOutputFile(videoFile.getAbsolutePath());// 把摄像头捕获的预览画面输送到屏幕mediaRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface());// 开始刻录// 进行缓存mediaRecorder.prepare();mediaRecorder.start();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}recorderbutton.setEnabled(false);stopbutton.setEnabled(true);break;case R.id.stopbutton:if(mediaRecorder!=null){mediaRecorder.stop();mediaRecorder.release();mediaRecorder=null;}recorderbutton.setEnabled(true);stopbutton.setEnabled(false);break;}}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubif (event.getAction() == MotionEvent.ACTION_DOWN) {// 设置可见layout.setVisibility(ViewGroup.VISIBLE);}return super.onTouchEvent(event);}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复