I finally got it to record videos. The preview surfcae works fine and
the audio stream of the audio resulting file is also okay. But the
video stream is a complete messup because you cannot figure out what
it is. The main part of the screen is filled with green colours.
Any idea what could be the reason? I tried all codec/container,
resolution and framerate variations, without success.
here is the code:
public class CamcorderPreview extends SurfaceView implements
SurfaceHolder.Callback {
private MediaRecorder recorder;
private SurfaceHolder holder;
public CamcorderPreview(Context context, AttributeSet attrs) {
super(context, attrs);
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
recorder = new MediaRecorder();
//recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//recorder.setAudioEncoder
(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder
(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setVideoSize(480, 320);
recorder.setVideoFrameRate(15);
//recorder.setMaxDuration(5000);
recorder.setOutputFile("/sdcard/dcim/100ANDRO/test.mp4");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int
width, int height){
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
public void startRecording(){
if(recorder != null){
recorder.start();
}
}
public void stopRecording(){
if(recorder != null){
recorder.stop();
recorder.release();
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---