Hi I'm trying to get the Videorecording/previewing to work but i keep getting errors.
heres what i've done:
manifest.xml
Code:
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.RECORD_VIDEO"></uses-permission>
camera_preview.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<SurfaceView
android:id="@+id/SurfaceView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</SurfaceView>
</RelativeLayout>
VideoCamera.java
Code:
package se.rijad.android.nikita.ui;
import java.io.IOException;
import se.rijad.android.nikita.R;
import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
public class VideoCamera extends Activity implements SurfaceHolder.Callback
{
private MediaRecorder mediaRecorder;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video_camera);
SurfaceView surface = (SurfaceView)findViewById(R.id.SurfaceView01);
SurfaceHolder holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400,300);
}
public void surfaceCreated(SurfaceHolder holder) {
if (mediaRecorder == null){
try {
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
//PREF THIS!
//mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
mediaRecorder.setOutputFile("/sdcard/nikita_video_output.mp4");
mediaRecorder.setPreviewDisplay(holder.getSurface());
mediaRecorder.prepare();
} catch (IllegalArgumentException e) {
Log.d("NIKITA{MEDIA_PLAYER}", e.getMessage());
} catch (IllegalStateException e) {
Log.d("NIKITA{MEDIA_PLAYER}", e.getMessage());
} catch (IOException e) {
Log.d("NIKITA{MEDIA_PLAYER}", e.getMessage());
}
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
public void surfaceDestroyed(SurfaceHolder holder) {
mediaRecorder.release();
}
}
Logcat
Code:
06-18 14:11:46.495: ERROR/AndroidRuntime(3458): Uncaught handler: thread main exiting due to uncaught exception
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.rijad.android.nikita/se.rijad.android.nikita.ui.VideoCamera}: java.lang.NullPointerException
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.os.Looper.loop(Looper.java:123)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread.main(ActivityThread.java:4595)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at java.lang.reflect.Method.invoke(Method.java:521)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at dalvik.system.NativeStart.main(Native Method)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): Caused by: java.lang.NullPointerException
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at se.rijad.android.nikita.ui.VideoCamera.onCreate(VideoCamera.java:24)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
06-18 14:11:46.505: ERROR/AndroidRuntime(3458): ... 11 more
VideoCamera.jva:24
Code:
SurfaceView surface = (SurfaceView)findViewById(R.id.surface);
SurfaceHolder holder = surface.getHolder();
24: holder.addCallback(this); //Null? :(
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400, 300);
please help.