Why is the above codes in .java file not recording any video

All your problems with Audio, Video and Images.

Why is the above codes in .java file not recording any video

Postby imso » Mon Mar 28, 2011 4:28 am

Because i doing an android application similar to this apps
http://www.androidzoom.com/android_appl ... shots.html
but it seems like the above code i copied in this website http://integratingstuff.com/2010/10/18/ ... n-android/ does not seems to allow me record any videos and saving it into an SD Card location? What should i do to get the video recorded and saving into a sd card.. Can someone help me i'm actually new in Eclipse and java programming so pardon me for any stupid thing i do in programming..

.java file
Code: Select all
package net.learn2develop.CameraTest;

import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;

public class CameraTest extends Activity implements SurfaceHolder.Callback {
   
   private static final String TAG ="CAMERA_TUTORIAL";
   
   private SurfaceView surfaceView;
   private SurfaceHolder surfaceHolder;
   private Camera camera;
   private boolean previewRunning;

   File tempFile = null;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        surfaceView = (SurfaceView)findViewById(R.id.surface_camera);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
       
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
       camera = Camera.open();
       if (camera != null) {
          Camera.Parameters params = camera.getParameters();
          camera.setParameters(params);
       }
       else {
          Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
          finish();
       }
    }
   
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
       if (previewRunning) {
          camera.stopPreview();
       }
       Camera.Parameters p = camera.getParameters();
       p.setPreviewSize(width, height);
       p.setPreviewFormat(PixelFormat.JPEG);
       //camera.setParameters(p);
       
       try {
             camera.setPreviewDisplay(holder);
             camera.startPreview();
             previewRunning = true;
       }
       catch (IOException e) {
          Log.e(TAG,e.getMessage());
          e.printStackTrace();
       }
    }
   
    @Override
    public void surfaceDestroyed(SurfaceHolder holder){
          camera.stopPreview();
          previewRunning = false;
          camera.release();
    }
   
    private MediaRecorder mediaRecorder;
    private final int maxDurationInMs = 20000;
    private final long maxFileSizeInBytes = 500000;
    private final int videoFramesPerSecond = 20;
   
    public boolean startRecording(){
       try {
             camera.unlock();
             
             mediaRecorder = new MediaRecorder();
             
             mediaRecorder.setCamera(camera);
             
             mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   
             mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
   
             mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
                
             mediaRecorder.setMaxDuration(maxDurationInMs);
                
                tempFile = new File(getCacheDir(),"1.3gp");
                mediaRecorder.setOutputFile(tempFile.getPath());
                
                mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
                mediaRecorder.setVideoSize(surfaceView.getWidth(),surfaceView.getHeight());
                
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
                
                mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
                
                mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
                
                      mediaRecorder.setMaxFileSize(maxFileSizeInBytes);
                            
                      mediaRecorder.prepare();
                      mediaRecorder.start();   
                      return true;
                            
       } catch (IllegalStateException e) {
          Log.e(TAG,e.getMessage());
          e.printStackTrace();
          return false;
       } catch (IOException e) {
          Log.e(TAG,e.getMessage());
          e.printStackTrace();
          return false;
       }
    }
   
    public void stopRecording(){
       mediaRecorder.stop();
       camera.lock();
    }
}


.xml file
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
    <RelativeLayout
         android:id="@+id/relativeLayout1"
        android:layout_height="match_parent"
       android:layout_width="match_parent">
        <Button
        android:text="Video"
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ></Button>
        <Button
        android:text="Setting"
        android:id="@+id/button2"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        ></Button>
        <Button
        android:text="Back"
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button2"
        ></Button>
        <Button
        android:text="Start"
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button3"
        ></Button>
        <SurfaceView
        android:id="@+id/surface_camera"
        android:layout_width="480dp"
        android:layout_height="320dp"
        android:layout_alignParentRight="true"
        ></SurfaceView>
        <TextView
        android:text="TextView"
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/button2"
        ></TextView>
        <TextView
        android:text="TextView"
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ></TextView>
        <TextView
        android:text="TextView"
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        ></TextView>       
         </RelativeLayout>
</FrameLayout>
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Top

Re: Why is the above codes in .java file not recording any v

Postby raj_J2ME » Wed Mar 30, 2011 12:35 pm

Just asking for conformation, are you testing the app on the emulator or on the real device?
Video recording is available only on handsets having version of SDK 1.5 or later. It is not possible to check application on emulator, you need to install it on handset.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Why is the above codes in .java file not recording any v

Postby imso » Wed Mar 30, 2011 12:48 pm

Yes its connected to an android handset.. i wanted to allow the surfacebview to allow the initiation of the recording and stop recording of the video something you would see in youtube but i don't know how? How should i come about doing it?
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 6 guests