I'm trying to create a simple camcorder application using mediarecorder and have spent 12+ hours trying to get it to work... its been frustrating as all hell. I've searched all over for the solution and attempted to use multiple pieces of sample code but still can't get it to work. The program keeps crashing and I get errors when I call prepare on the mediarecorder.
Layout Below ////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/camera_layout" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<android.view.SurfaceView android:id="@+id/preview"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</android.view.SurfaceView>
<Button android:id="@+id/start_video" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Start Video">
</Button>
<Button android:id="@+id/stop_video" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Stop Video"
android:layout_toRightOf="@id/start_video">
</Button>
</RelativeLayout>
Code Below ////////////////////////////////////////////////////////////////
public class start extends Activity
{
private SurfaceView preview;
private SurfaceHolder previewHolder;
private String locationName;
private String filepath;
private File video;
public void onCreate(Bundle videocawk) {
super.onCreate(videocawk);
setContentView(R.layout.video_layout);
setSurface();
//locationName = getIntent().getStringExtra("locationName");
locationName = "dan";
filepath = getFilePath(locationName);
try {
MediaRecorder r = getMediaRecorder(filepath, previewHolder.getSurface());
setButtonListeners(r);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String getFilePath(String locName) {
String dir = Environment.getExternalStorageDirectory().getPath();
String add = "/vext/";
String name = locName + " -- 1";
String total = dir + add + name;
video = new File(total);
return total;
}
private void setSurface() {
preview = (SurfaceView) findViewById(R.id.preview);
previewHolder = preview.getHolder();
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
private void setButtonListeners(final MediaRecorder r) {
Button start = (Button) findViewById(R.id.start_video);
Button end = (Button) findViewById(R.id.stop_video);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startRecording(r);
}
});
end.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stopRecording(r);
finish();
}
});
}
private void startRecording(MediaRecorder r) {
r.start();
}
private void stopRecording(MediaRecorder r) {
r.stop();
}
private MediaRecorder getMediaRecorder(String filepath, Surface s)
throws IllegalStateException, IOException {
MediaRecorder m_recorder = new MediaRecorder();
m_recorder.setPreviewDisplay(s);
m_recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
m_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
m_recorder.setMaxDuration(20000); // length of video in MS
m_recorder.setVideoSize(320, 240);
m_recorder.setVideoFrameRate(15);
m_recorder.setOutputFile(video.getPath());
m_recorder.prepare();
return m_recorder;
}
}
The errors I get are:
07-18 19:43:40.044: ERROR/audio_input(987): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value
07-18 19:43:40.044: ERROR/audio_input(987): VerifyAndSetParameter failed
07-18 19:43:40.044: ERROR/CameraInput(987): Unsupported parameter(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value)
07-18 19:43:40.044: ERROR/CameraInput(987): VerifiyAndSetParameter failed on parameter #0
HELP PLEASE!!!!