How can i solve these two problems?
thanks very much.
here are my codes:
CamcorderPreview
Using java Syntax Highlighting
- public class CamcorderPreview extends SurfaceView implements
- SurfaceHolder.Callback {
- MediaRecorder recorder;
- SurfaceHolder holder;
- private Camera mCamera;
- public CamcorderPreview(Context context, AttributeSet attrs) {
- super(context, attrs);
- holder = getHolder();
- holder.addCallback(this);
- holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- recorder = new MediaRecorder();
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
- recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
- // recorder.setVideoSize(480, 320);
- // recorder.setVideoFrameRate(15);
- // recorder.setMaxDuration(10000);
- }
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
- }
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- recorder.setOutputFile("/sdcard/" + System.currentTimeMillis() + ".mp4");
- recorder.setPreviewDisplay(holder.getSurface());
- if (recorder != null) {
- try {
- recorder.prepare();
- } catch (IllegalStateException e) {
- Log.e("IllegalStateException", e.toString());
- } catch (IOException e) {
- Log.e("IOException", e.toString());
- }
- }
- }
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- }
- public MediaRecorder getRecorder() {
- return recorder;
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
CamcorderActivity
Using java Syntax Highlighting
- public class CamcorderActivity extends Activity {
- private CamcorderPreview camcorderPreview;
- private boolean recording = false;
- SurfaceHolder holder;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- setContentView(R.layout.main);
- Toast.makeText(CamcorderActivity.this, "点击屏幕开始摄像,再次点击完成摄像",
- Toast.LENGTH_LONG).show();
- camcorderPreview = (CamcorderPreview) findViewById(R.id.camcorder_preview);
- camcorderPreview.setOnTouchListener(new OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- if (recording) {
- recording = false;
- camcorderPreview.getRecorder().stop();
- //amcorderPreview.getRecorder().release();
- Toast.makeText(CamcorderActivity.this, "摄像完成",
- Toast.LENGTH_LONG).show();
- // Intent intent = new Intent();
- //intent.setClass(CamcorderActivity.this, CamcorderActivity.class);
- //startActivity(intent);
- //
- } else {
- recording = true;
- camcorderPreview.getRecorder().start();
- Toast.makeText(CamcorderActivity.this, "正在摄像......",
- Toast.LENGTH_LONG).show();
- }
- return true;
- }
- return false;
- }
- });
- }
- }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <com.CamcorderActivity.CamcorderPreview android:id="@+id/camcorder_preview"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:enabled="false" android:focusable="true" android:clickable="true" />
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Thanks again.

