Code example for Camera

Methods: lockunlock

0
	 
    private boolean prepareVideoRecorder(){ 
        mMediaRecorder = new MediaRecorder();
 
        // Step 1: Unlock and set camera to MediaRecorder 
        camera.unlock();
        mMediaRecorder.setCamera(camera);
 
        // Step 2: Set sources 
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
 
        // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) 
        //mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); 
  
         
        // Step 3: Set output format and encoding (for versions prior to API Level 8) 
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
         
        // Step 4: Set output file 
        mMediaRecorder.setOutputFile(ls.getFileDescriptor());
         
        // Step 5: Set the preview output 
        //mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 
        mMediaRecorder.setPreviewDisplay(holder.getSurface());
         
        Log.i(TAG, "Surface valid: "+holder.getSurface().isValid());
 
        /*mMediaRecorder.setVideoSize(176, 144); 
        mMediaRecorder.setVideoFrameRate(20); 
        mMediaRecorder.setAudioChannels(1); 
        */ 
         
        // Step 6: Prepare configured MediaRecorder 
        try { 
            mMediaRecorder.prepare();
        } catch (Exception e) {
            Log.d(TAG, "Exception preparing MediaRecorder: " + e.getMessage());
            releaseMediaRecorder(); 
            return false; 
        } 
        return true; 
    } 
	 
     
    private void releaseMediaRecorder(){ 
        if (mMediaRecorder != null) {
            mMediaRecorder.reset();
            mMediaRecorder.release();
            mMediaRecorder = null;
            camera.lock();
        } 
    } 
	 
    private void releaseCamera(){ 
        if (camera != null){