티스토리 뷰
package apptlantis.si.hong;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.VideoView;
public class RecordVideoActivity extends Activity implements SurfaceHolder.Callback{
private static final String OUTPUT_FILE = "/sdcard/videooutput.mp4";
private static final String OUTPUT_FILE_NAME = "videooutput.mp4";
private static final int RECORDING_TIME = 30000;
private VideoView mVideoView = null;
private SurfaceHolder holder;
private Camera mCamera = null;
private MediaRecorder recorder = null;
boolean recording = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("onclick", "click");
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.video);
SurfaceView cameraView = (SurfaceView) findViewById(R.id.surfaceView);
holder = cameraView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Button recStart = (Button)findViewById(R.id.startBtn);
recStart.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
recorder.start();
}
});
Button recStop = (Button)findViewById(R.id.stopBtn);
recStop.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
recorder.stop();
/*initRecorder();
prepareRecorder();*/
TCPClient tp = new TCPClient(OUTPUT_FILE, OUTPUT_FILE_NAME);
tp.run();
}
});
}
private void initRecorder() {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile(OUTPUT_FILE);
recorder.setMaxDuration(RECORDING_TIME);
recorder.setMaxFileSize(10485760); // Approximately 5 megabytes
}
private void prepareRecorder() {
recorder.setPreviewDisplay(holder.getSurface());
//recorder.setOrientationHint(90);
try {
recorder.prepare();
//finish();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
prepareRecorder();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
if (recording) {
recorder.stop();
recording = false;
}
recorder.release();
finish();
}
class mySurfaceView extends SurfaceView {
public mySurfaceView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.view.SurfaceView#draw(android.graphics.Canvas)
*/
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);
}
}
}
동영상 촬영 하면서 화면을 SurfaceView에 보여줍니다.
'프로그래밍 > 모바일' 카테고리의 다른 글
네트워크 오류 (0) | 2012.01.16 |
---|---|
[안드로이드]텍스트를 넣을 수 있는 다이얼로그를 만들어봅시다. (5) | 2011.12.26 |
numberpicker (0) | 2011.12.12 |
[안드로이드] 사운드 재생에 대한 좋은 글 (0) | 2011.10.28 |
[안드로이드]커스텀뷰에서 맵정보를 이용해서 그려주고 싶을 때 (0) | 2011.10.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday