I am a student doing my task of Android APPs. And I got a problem I can t fix.Pls give me some advice, thx. I want to have an activity of video recording, and I have done by using this code. Video recording with media recorder And here is my code, it work fine in other phone but it didnt work fine in moto-razr here are two video taking by HTC desire and MOTO razr. desire:http://youtu.be/suPF9Hk6iYk razr:http://youtu.be/wLvH7SXdcIs Can any one help me to fix my problem?
package video.pac;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Display;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
public class video extends Activity{
private MediaRecorder recorder;
private Preview mPreview;
boolean flag=false;
boolean startedRecording=false;
boolean stoppedRecording=false;
boolean key = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(640,480);
recorder.setVideoFrameRate(20);
recorder.setVideoEncodingBitRate(3000000);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
//recorder.setMaxDuration(5000);
mPreview = new Preview(video.this,recorder);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(mPreview);
}
private CountDownTimer mCountDownTimer = new CountDownTimer(9000, 1000) {
public void onTick(long millisUntilFinished) {}
public void onFinish() {
recorder = null;
System.out.println("stop");
video.this.finish();
}
};
class stopThread implements Runnable {
public void run() {
try {
mCountDownTimer.start();
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
class Preview extends SurfaceView implements SurfaceHolder.Callback{
//Create objects for MediaRecorder and SurfaceHolder.
SurfaceHolder mHolder;
MediaRecorder tempRecorder;
public Preview(Context context,MediaRecorder recorder) {
super(context);
tempRecorder=recorder;
mHolder=getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
// TODO Auto-generated constructor stub
}
public Surface getSurface(){
return mHolder.getSurface();
}
public void surfaceCreated(SurfaceHolder holder){
tempRecorder.setOutputFile("/sdcard/test" + ".3gpp");
tempRecorder.setPreviewDisplay(mHolder.getSurface());
try{
tempRecorder.prepare();
recorder.start();
new Thread(new stopThread()).start();
System.out.println("start");
} catch (Exception e) {
tempRecorder.release();
tempRecorder = null;
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
if(tempRecorder!=null){
tempRecorder.stop();
tempRecorder.release();
tempRecorder = null;
System.out.println("release");
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {}
}
}