package com.cn.mvideo;
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.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MVideo extends Activity {
private File myRecAudioFile;
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private Button buttonStart;
private Button buttonStop;
private File dir;
private MediaRecorder recorder;
private String SD_CARD_TEMP_DIR = getSDPath() File.separator "myvideo"
File.separator;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSurfaceView = (SurfaceView) findViewById(R.id.videoView);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
buttonStart = (Button) findViewById(R.id.start);
buttonStop = (Button) findViewById(R.id.stop);
dir = new File(SD_CARD_TEMP_DIR);
if (!dir.exists()) {
dir.mkdir();
}
recorder = new MediaRecorder();
buttonStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
recorder();
}
});
buttonStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
});
}
public void recorder() {
try {
myRecAudioFile = File.createTempFile("video", ".3gp", dir);// 创建临时文件
recorder.setPreviewDisplay(mSurfaceHolder.getSurface());// 预览
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // 录音源为麦克风
recorder.setMaxDuration(10000);// 最大期限
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // 从照相机采集视频
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setVideoSize(480, 320);
recorder.setVideoFrameRate(3); // 每秒3帧
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); // 设置视频编码方式
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(myRecAudioFile.getAbsolutePath());// 保存路径
recorder.prepare();
recorder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getSDPath() {
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();// 获取跟目录
} else {
return null;
}
System.out.println("sd路径是:" sdDir.toString());
return sdDir.toString();
}
}
资源文件列表
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/.classpath , 364
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/.project , 842
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/AndroidManifest.xml , 991
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes.dex , 5500
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/MVideo$1.class , 740
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/MVideo$2.class , 1005
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/MVideo.class , 3761
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R$attr.class , 325
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R$drawable.class , 392
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R$id.class , 429
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R$layout.class , 379
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R$string.class , 412
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/classes/com/cn/mvideo/R.class , 496
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/MVideo.apk , 15820
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/resources.ap_ , 11241
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/res/drawable-hdpi/ic_launcher.png , 3966
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/res/drawable-ldpi/ic_launcher.png , 1537
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/bin/res/drawable-mdpi/ic_launcher.png , 2200
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/gen/com/cn/mvideo/R.java , 841
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/proguard.cfg , 1248
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/project.properties , 360
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/res/drawable-hdpi/ic_launcher.png , 4147
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/res/drawable-ldpi/ic_launcher.png , 1723
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/res/drawable-mdpi/ic_launcher.png , 2574
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/res/layout/main.xml , 1105
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/res/values/strings.xml , 178
android安卓视频录制摄像拍摄源码(测试可用)/MVideo/src/com/cn/mvideo/MVideo.java , 2822
