Why the video is saved to a local file is empty, is not it conflicts with the Camera or something, do a few days, seeking help, how to solve it?
public class SocketCamera extends SurfaceView implements
Camera.PreviewCallback, SurfaceHolder.Callback {
public SocketCamera (Context arg0) {
super (arg0);
}
private SurfaceHolder mSurfaceHolder = null;
private Camera mCamera = null;
private File myRecAudioFile;
private File dir;
private MediaRecorder recorder;
public String sdcardDir = "/ mnt / extsd / video /";
/ ** Server name * /
private String pUsername = "XZY";
/ ** Video quality * /
private int VideoQuality = 85;
/ ** Send video width ratio * /
private float VideoWidthRatio = 100;
/ ** Send video height ratio * /
private float VideoHeightRatio = 100;
/ ** Send video resolution width * /
private int VideoWidth = 0;
/ ** Send video resolution height * /
private int VideoHeight = 0;
/ ** Video format index * /
private int VideoFormatIndex = 0;
public void init (int Width, int Height) {
VideoHeight = Height;
VideoWidth = Width;
mSurfaceHolder = getHolder ();
mSurfaceHolder.addCallback (this);
mSurfaceHolder.setType (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
VideoWidthRatio = VideoWidthRatio / 100f;
VideoHeightRatio = VideoHeightRatio / 100f;
new MySendCommondThread ("PHONECONNECT |" + pUsername + "|") start ();.
if (recorder == null) {
recorder = new MediaRecorder ();
}
InitCamera ();
recorder ();
}
private void InitCamera () {
try {
mCamera = Camera.open ();
} Catch (Exception e) {
e.printStackTrace ();
}
}
public void recorder () {
dir = new File (sdcardDir);
if (! dir.exists ()) {
dir.mkdir ();
}
try {
myRecAudioFile = File
.createTempFile ("SP" + new SimpleDateFormat ("yyyyMMdd_hhmmss") format (new Date (System.currentTimeMillis ())), "3gp.", dir.); // create a temporary file
// Recorder.setAudioSource (MediaRecorder.AudioSource.MIC); //
// Recording source microphone
// Recorder.setMaxDuration (10000); // maximum period
recorder.setCamera (mCamera);
recorder.setVideoSource (MediaRecorder.VideoSource.CAMERA); // to capture video from a camera
recorder.setOutputFormat (MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder (MediaRecorder.VideoEncoder.H264); // Set video encoding
recorder.setVideoSize (320, 240);
recorder.setVideoFrameRate (20); // 20 frames per second
// Recorder.setPreviewDisplay (mSurfaceHolder.getSurface ()); // Preview
recorder.setOutputFile (myRecAudioFile.getAbsolutePath ()); // save path
recorder.prepare ();
recorder.start ();
} Catch (IOException e) {
e.printStackTrace ();
}
}
Override
public void surfaceChanged (SurfaceHolder holder, int format, int width,
int height) {
if (mCamera == null) {
return;
}
mCamera.stopPreview ();
mCamera.setPreviewCallback (this);
Camera.Parameters parameters = mCamera.getParameters ();
Size size = parameters.getPreviewSize ();
VideoWidth = size.width;
VideoHeight = size.height;
VideoFormatIndex = parameters.getPreviewFormat ();
mCamera.startPreview ();
}
Override
public void surfaceCreated (SurfaceHolder holder) {
// TODO Auto-generated method stub
try {
if (mCamera! = null) {
mCamera.setPreviewDisplay (mSurfaceHolder);
mCamera.startPreview ();
}
} Catch (IOException e) {
e.printStackTrace ();
}
}
Override
public void surfaceDestroyed (SurfaceHolder holder) {
// TODO Auto-generated method stub
if (null! = mCamera) {
mCamera.setPreviewCallback (null);
mCamera.stopPreview ();
mCamera.release ();
mCamera = null;
}
if (null! = recorder) {
recorder.stop ();
recorder.reset ();
recorder.release ();
recorder = null;
}
}
Override
public void onPreviewFrame (byte [] data, Camera camera) {
// TODO Auto-generated method stub
try {
if (data! = null) {
YuvImage image = new YuvImage (data, VideoFormatIndex,
VideoWidth, VideoHeight, null);
if (image! = null) {
ByteArrayOutputStream outstream = new ByteArrayOutputStream ();
image.compressToJpeg (new Rect (0, 0,
(Int) (VideoWidthRatio * VideoWidth),
(Int) (VideoHeightRatio * VideoHeight)),
VideoQuality, outstream);
outstream.flush ();
Thread th = new MySendFileThread (outstream, pUsername,
Constant.SRVIP, 8511);
th.start ();
}
}
} Catch (IOException e) {
e.printStackTrace ();
}
}
}
Reply:
File has been 0kb or do not understand how going on?

Reply:
Help ah help ~~~
Reply:
Will the landlord your problem resolved? It is how to solve it?
Reply:
No comments:
Post a Comment