How do i name my video file in the format of DateTime?

Put your problem here if it does not fit any of the other categories.

How do i name my video file in the format of DateTime?

Postby imso » Sat Apr 02, 2011 7:47 am

I want my video file format such as every newly recorded video file will be name its current date and time it is being recorded and saving it into an folder in an sd card? Eg: 2011-04-01 16:49:15 Can someone help me please, it ry reading lots of site on this still not knowing how to do it, is it using import java.util or something else can someone help me do i need some sort of method in order to do this?? I'm very new to eclipse and java can someone guide me on this...

Code: Select all
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);
       
        Button btnStart = (Button) findViewById(R.id.button4);
        btnStart.setOnClickListener(new View.OnClickListener()
        {
           public void onClick(View v)
           {
              startRecording();
              Toast.makeText(getBaseContext(), "Recording Started", Toast.LENGTH_SHORT).show();
           }
           
        });
       
        Button btnStop = (Button) findViewById(R.id.button5);
        btnStop.setOnClickListener(new View.OnClickListener()
        {
           public void onClick(View v)
           {
              stopRecording();
              Toast.makeText(getBaseContext(), "Recording Stopped", Toast.LENGTH_SHORT).show();   
           }
        });
    }
    @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(320, 240);
       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 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);
               
               
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
               
                mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
               
                //mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
               
                tempFile = new File(Environment.getExternalStorageDirectory(),"1.3gp");
                mediaRecorder.setOutputFile(tempFile.getPath());
               
                mediaRecorder.setVideoSize(surfaceView.getWidth(),surfaceView.getHeight());
               
                //mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
               
                mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
                         
                      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();
    }
}
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests