2011年6月30日 星期四

錄製mp4檔案

package com.demo.android.test;

import java.io.File;

import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;

public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

File file = new File("/storage/test.mp4");

try
{
if(!file.exists())
{
if(file.createNewFile())
{
Log.e("debug","create empty file successful.");
}
else
{
Log.e("debug","create empty file failure.");
}
}
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/storage/test.mp4");
recorder.prepare();
Log.e("debug","recorder start ....");
recorder.start(); // Recording is now started
Thread.sleep(60000);
Log.e("debug","reorder stop....");
recorder.stop();
}
catch(Exception ex)
{
Log.e("debug",ex.toString());
}
}
}

沒有留言: