i have written a sample program to record the video (camcorder application).
when i run the program using the emulator (i have android-sdk-windows-1.5_r3) i get
Using java Syntax Highlighting
- java.io.IOException: prepare failed.
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- MediaRecorder.prepare()
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- CamcorderActivity.surfaceCreated()
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
above errors are seen in logcat output...
BUT i can see the activity launched and camera preview ... again the preview is seen only in half of the screen !
its weird!!!
further when i do
Using java Syntax Highlighting
- recorder.start()
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- java.lang.IllegalStateException
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
can someone please help me ... to understand whats happening here !
btw ... i have attached the logs and the screen shot !
thanks in advance
~pp
My code ...
Using java Syntax Highlighting
- package com.example;
- import java.io.IOException;
- import android.app.Activity;
- import android.graphics.PixelFormat;
- import android.media.MediaRecorder;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
- public class CamcorderActivity extends Activity implements
- SurfaceHolder.Callback
- {
- private MediaRecorder recorder;
- private SurfaceView surfaceView;
- private SurfaceHolder surfaceHolder;
- private boolean recording = false;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- // configure the surface
- getWindow().setFormat(PixelFormat.TRANSLUCENT);
- setContentView(R.layout.main);
- surfaceView = (SurfaceView) findViewById(R.id.camcordersurface);
- surfaceHolder = surfaceView.getHolder();
- surfaceHolder.addCallback(this);
- surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- configureRecorder();
- }
- private void configureRecorder()
- {
- // configure media recorder
- 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);
- }
- private void stopRecorder()
- {
- try
- {
- if (recorder == null)
- {
- return;
- }
- recorder.stop();
- recorder.reset();
- recorder.release();
- recording = false;
- recorder = null;
- }
- finally
- {
- if (recorder != null)
- {
- recorder.release();
- }
- }
- }
- private void startRecorder()
- {
- recorder.start();
- recording = true;
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
- {
- // if not recording then start
- if (!recording)
- {
- startRecorder();
- }
- else
- {
- // if already recording then stop
- stopRecorder();
- finish();
- }
- return true;
- }
- return super.onKeyDown(keyCode, event);
- }
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height)
- {
- // do nothing
- }
- @Override
- public void surfaceCreated(SurfaceHolder holder)
- {
- recorder.setOutputFile("/sdcard/test" + System.currentTimeMillis()
- + ".mp4");
- recorder.setPreviewDisplay(holder.getSurface());
- try
- {
- recorder.prepare();
- }
- catch (IOException e)
- {
- Log.e("error -- ", e.toString(), e);
- // TODO:
- // show error message
- }
- }
- @Override
- public void surfaceDestroyed(SurfaceHolder holder)
- {
- stopRecorder();
- }
- }
Parsed in 0.048 seconds, using GeSHi 1.0.8.4
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">
- <SurfaceView android:id="@+id/camcordersurface"
- android:layout_width="fill_parent" android:layout_height="10dip"
- android:layout_weight="1">
- </SurfaceView>
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

