Hi, i'm seeing same issue. were you able to find a solution?
thx, Mikhail. On Sep 8, 3:49 am, preetam_pict <preetam.pa...@gmail.com> wrote: > Hi all > > I am trying to write a sample program to record the video (say > camcorder application). > When i run my program using the emulator (I have android-sdk- > windows-1.5_r3) I see java.io.IOException:preparefailed. error in > logcat output. > > Further I can see that I have came across this error when i call > MediaRecorder.prepare() > from CamcorderActivity.surfaceCreated() > But I am surprised to see that activity got launched and I am seeing > the camera preview! Again the preview is seen only in half of the > screen! Its weird!!! > > Further when i do recorder.start() to record the video I get > java.lang.IllegalStateException. Yes this is obvious since theprepare > () has failed. > But the question is whyprepare() has failed ? > > Can someone please help me to understand whats happening here! > Am i missing something ??? > > thanks in advance > ~pp > > Here is my code ... > 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(); > } > > } > > And the layout ... > > <?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> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---