Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Whats wrong with the above video codes?

Whats wrong with the above video codes?

All your problems with Audio, Video and Images.

Whats wrong with the above video codes?

Postby imso » Thu Mar 24, 2011 6:18 am

After i run the above codes it seems that it is not recording any video and saving it onto the sd card> Can someone help me with this problem? By the way i'm kinna new in java and eclipse, Thanks.. These code below is written on .java file.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package net.learn2develop.Video;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import android.app.Activity;
  7. import android.graphics.PixelFormat;
  8. import android.hardware.Camera;
  9. import android.media.MediaRecorder;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.SurfaceHolder;
  13. import android.view.SurfaceView;
  14. import android.widget.Toast;
  15.  
  16. public class VideoActivity extends Activity implements SurfaceHolder.Callback{
  17. private static final String TAG ="CAMERA_TUTORIAL";
  18.        
  19.         private SurfaceView surfaceView;
  20.         private SurfaceHolder surfaceHolder;
  21.         private Camera camera;
  22.         private boolean previewRunning;
  23.        
  24.         File tempFile = null;
  25.    
  26.     @Override
  27.     public void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.main);
  30.         surfaceView = (SurfaceView)
  31.         findViewById(R.id.surface_camera);
  32.         surfaceHolder = surfaceView.getHolder();
  33.         surfaceHolder.addCallback(this);
  34.        
  35.         surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  36.     }
  37.     @Override
  38.     public void surfaceCreated(SurfaceHolder holder) {
  39.         camera = Camera.open();
  40.         if (camera != null) {
  41.                 Camera.Parameters params = camera.getParameters();
  42.                 camera.setParameters(params);
  43.         }
  44.         else {
  45.                 Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
  46.                 finish();
  47.         }
  48.     }
  49.    
  50.     @Override
  51.     public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
  52.         if (previewRunning) {
  53.                 camera.stopPreview();
  54.         }
  55.         Camera.Parameters p = camera.getParameters();
  56.         p.setPreviewSize(width, height);
  57.         p.setPreviewFormat(PixelFormat.JPEG);
  58.         //camera.setParameters(p);
  59.        
  60.         try {
  61.                         camera.setPreviewDisplay(holder);
  62.                         camera.startPreview();
  63.                         previewRunning = true;
  64.         }
  65.         catch (IOException e) {
  66.                 Log.e(TAG,e.getMessage());
  67.                 e.printStackTrace();
  68.         }
  69.     }
  70.    
  71.     @Override
  72.     public void surfaceDestroyed(SurfaceHolder holder){
  73.                 camera.stopPreview();
  74.                 previewRunning = false;
  75.                 camera.release();
  76.     }
  77.    
  78.     private MediaRecorder mediaRecorder;
  79.     private final int maxDurationInMs = 20000;
  80.     private final long maxFileSizeInBytes = 500000;
  81.     private final int videoFramesPerSecond = 20;
  82.    
  83.     public boolean startRecording(){
  84.         try {
  85.                         camera.unlock();
  86.                        
  87.                         mediaRecorder = new MediaRecorder();
  88.                        
  89.                         mediaRecorder.setCamera(camera);
  90.                        
  91.     mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  92.    
  93.     mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  94.    
  95.     mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
  96.                                
  97.                                 mediaRecorder.setMaxDuration(maxDurationInMs);
  98.                                
  99.                                 tempFile = new File(getCacheDir(),"1.3gp");
  100.                                 mediaRecorder.setOutputFile(tempFile.getPath());
  101.                                
  102.                                 mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
  103.                                 mediaRecorder.setVideoSize(surfaceView.getWidth(),surfaceView.getHeight());
  104.                                
  105.                                 mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
  106.                                
  107.                                 mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
  108.                                
  109.                                 mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
  110.                                
  111.                                                                 mediaRecorder.setMaxFileSize(maxFileSizeInBytes);
  112.                                                                
  113.                                                                 mediaRecorder.prepare();
  114.                                                                 mediaRecorder.start();
  115.                                                                
  116.                                                                 return true;
  117.                                                                
  118.         } catch (IllegalStateException e) {
  119.                 Log.e(TAG,e.getMessage());
  120.                 e.printStackTrace();
  121.                 return false;
  122.         } catch (IOException e) {
  123.                 Log.e(TAG,e.getMessage());
  124.                 e.printStackTrace();
  125.                 return false;
  126.         }
  127.     }
  128.    
  129.     public void stopRecording(){
  130.         mediaRecorder.stop();
  131.         camera.lock();
  132.     }
  133.     }
  134. }
Parsed in 0.017 seconds, using GeSHi 1.0.8.4
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 3 guests