title: MediaRecorder output 0 byte file
body: <p>I wanna record video and audio using MediaRecorder.</p>
  
  <p>It's work.</p>
  
  <p>But when i check output file.</p>
  
  <p>I can't play output video file.</p>
  
  <p>Because,</p>
  
  <p>output filesize is <code>0 byte.</code></p>
  
  <p>also video time is 0 second..</p>
  
  <p>Please check my code.</p>
  
  <pre><code>public class Talk extends Activity implements SurfaceHolder.Callback{
  
  Context context;
  
  
  SurfaceView sfv_Preview;
  private SurfaceHolder holder;
  private MediaRecorder recorder = null;
  boolean recording = false;
  
  private static final String OUTPUT_FILE = "/sdcard/videooutput.mp4";
  private static final String OUTPUT_FILE_NAME = "videooutput.mp4";
  private static final int RECORDING_TIME = 10000;
  
  //Uri fileUri;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_talk);
  
  
      recorder = new MediaRecorder();
      initRecorder();
  
      sfv_Preview = (SurfaceView) findViewById(R.id.sfv_Preview);
  
  
      holder = sfv_Preview.getHolder();
      holder.addCallback(this);
      holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
      context = this;
  
  
      ((ImageButton)findViewById(R.id.ibt_Record)).setOnTouchListener(new OnTouchListener(){
  
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              if (MotionEvent.ACTION_DOWN == event.getAction()) {
                  recorder.start();
                  Log.d("recod", "start");
              }
              else if (MotionEvent.ACTION_UP == event.getAction() || event.getAction() == MotionEvent.ACTION_CANCEL) {
                  Log.d("recod", "stop");
                  recorder.stop();
                  initRecorder();
                  prepareRecorder();
              }
              return false;
          }
      });
  
  }
  
  
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      // TODO Auto-generated method stub
      prepareRecorder();
  }
  
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width,
          int height) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
      // TODO Auto-generated method stub
      if (recording) {
          recorder.stop();
          recording = false;
      }
      recorder.release();
      finish();
  }
  
  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();
      }
  }
  
  }
  </code></pre>
  
  <p>What is problem?</p>