Android Open Source - EnergyWastingApp Video Camera






From Project

Back to project page EnergyWastingApp.

License

The source code is released under:

Copyright ? 2013-2014 Pekka Ekman <pekka.ekman@aalto.fi> 2013 Babujee Jerome Robin <robin.babujeejerome@aalto.fi> Permission is hereby granted, free of charge, to any person obtaining a ...

If you think the Android project EnergyWastingApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.aalto.pekman.energywastingapp.components;
/*w  w  w  .  j  a  v a2s. c  o  m*/
import android.annotation.TargetApi;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Build;
import android.util.Log;
import android.view.SurfaceHolder;

public class VideoCamera extends AbstractCamera {

  @Override
  public String getName() { return "Camera (video) & flash"; }

  private MediaRecorder recorder = null;

  /** UI component that shows the preview image from camera */
  private class Preview extends AbstractCamera.Preview {
    
    @TargetApi(8)
    protected void onStart(SurfaceHolder holder) {
      cam.unlock();
      
      recorder = new MediaRecorder();
      recorder.setCamera(cam);
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      
      // record video only with the highest supported profile
      if (Build.VERSION.SDK_INT >= 8) {
        CamcorderProfile p = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        recorder.setOutputFormat(p.fileFormat);
        recorder.setVideoFrameRate(p.videoFrameRate);
        recorder.setVideoSize(p.videoFrameWidth, p.videoFrameHeight);
        recorder.setVideoEncodingBitRate(p.videoBitRate);
        recorder.setVideoEncoder(p.videoCodec);
      } else {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
      }
      
      recorder.setOutputFile("/dev/null");
      recorder.setPreviewDisplay(holder.getSurface());
      
      try {
        recorder.prepare();
      } catch (Exception e) {
        Log.e("VideoCamera.Preview.onStart()", e.getMessage(), e);
        recorder.reset();
        recorder.release();
        recorder = null;
        onError();
        return;
      }
      recorder.start();
      
      Log.d("VideoCamera", "Recording video");
    }
    
    protected void onError() {
      stop();
      markTurnedOff();
    }
  }

  @Override
  public void start() {
    if (cam == null && isSupported())
      cam = getCamera();
    
    if (cam != null) {
      turnOnFlashlight();
      
      // create and add preview UI component
      addPreview(new Preview());
    }
    else
      markTurnedOff();
  }

  @Override
  public void stop() {
    Log.d("VideoCamera", "Stopping video recording");
    
    if (recorder != null) {
      recorder.stop();
      recorder.release();
      recorder = null;
    }
    if (cam != null) {
      cam.lock();
    }
    
    super.stop();
  }

}




Java Source Code List

fi.aalto.pekman.energywastingapp.MainActivity.java
fi.aalto.pekman.energywastingapp.components.AbstractCamera.java
fi.aalto.pekman.energywastingapp.components.AbstractFileWriter.java
fi.aalto.pekman.energywastingapp.components.AppDirFileWriter.java
fi.aalto.pekman.energywastingapp.components.BlueToothBurn.java
fi.aalto.pekman.energywastingapp.components.CPUBurn.java
fi.aalto.pekman.energywastingapp.components.Component.java
fi.aalto.pekman.energywastingapp.components.Display.java
fi.aalto.pekman.energywastingapp.components.ExtStorageFileWriter.java
fi.aalto.pekman.energywastingapp.components.GPSCoordSearch.java
fi.aalto.pekman.energywastingapp.components.RecordAudio.java
fi.aalto.pekman.energywastingapp.components.StillCamera.java
fi.aalto.pekman.energywastingapp.components.TonePlay.java
fi.aalto.pekman.energywastingapp.components.Vibration.java
fi.aalto.pekman.energywastingapp.components.VideoCamera.java
fi.aalto.pekman.energywastingapp.components.WiFiDataTransfer.java