Camera / Video Sample App

BSD2.0.txt
CameraPicture_WhitePaper.docx
CameraPicture.zip
OpenIconPD.txt

Cristiano Ferreira

Introduction

This sample shows how to use the Android* video API by recording a video for 5 seconds.

Activity:

The class itself needs to extend the activity class, which is basically an objective that summons a window for you with a single call. For now, it is just a blank window, but we will set what the user will see in the following method.

onCreate():

The activity contains an onCreate() method that is used for initialization. You can specify a window you would like to use via the setContentView() method. This sample in particular uses R.layout.camera_video. This is a premade UI specifically for taking video with the camera. In the sample we also set the SurfaceView to be the “preview” view. You are also making the link between your UI and code here. To summon the preview, we need to specify a callback for the preview holder.

onResume()

The onResume() function basically specifies what happens when the window is the object of focus. Whatever is specified in this function persists until onPause() is called. First we must call super.onResume() to do general built-in activity requirements. In the sample we use this function to get information about all of the cameras on the device, and then we start the camera. We specify to use the back facing camera first in this example.

onPause()

This function specifies what actions we want to take when the activity is no longer the center of attention. Since there is no longer a point in displaying a preview, we stop it and then release the camera reference. You must call super.onPause() at the end for general activity housekeeping.

onOptionsItemSelected(MenuItem)

This method checks if the preview view is activated. If so, it calls the recordVideo function, which starts recording the video.

recordVideo()

This is the function that actually does the recording. Before it uses the start method, all of the required properties need to be set in the MediaRecorder object. The properties to set include the output file information, audio source, and video source. We set all of these properties first, and then start our capture process. The app captures video for 5 seconds and then stops.

getBestPreviewSize(int, int, Camera.Parameters)

Finds the highest preview size supported on the device.

getSmallestPictureSize(Camera.Parameters)

Gets the smallest picture size supported on the device.

surfaceCreated(SurfaceHolder)

This is the specified callback function for creating the preview within the onCreate() function. You pass it the SurfaceHolder object you selected, and the function assigns it to the camera.PreviewDisplay property.

surfaceChanged()

This is where the surface holder is actually changed to the preview, and the inPreview flag is switched to true.

surfaceDestroyed()

A required method, but nothing needs to be released here.

Basic Lifecycle

  • Photo activity is called
    • onCreate() is called
      • Sets the view to camera_video layout.
      • Sets SurfaceView callback to surfaceCallback() to get a preview screen.
        • SurfaceCallback() sets camera.previewDisplay to the previewHolder variable we specified.
        • Calls surfaceChanged(), which sets the preview size and the smallestpicturesize by calling getBestPreviewSize and getSmallestPictureSize.
        • Sets up the preview window with all of the parameters specified.
    • onResume() is called
      • Enumerates cameras, looks for the back facing camera, and then opens it.
    • Preview screen is being displayed and is waiting on user interaction.
    • When user presses capture, onOptionsItemSelected() is called.
      • If the function is called while preview is being displayed, the camera.takePicture method calls photoCallback.

About Author

Cristiano was an intern with Intel from January-August 2012. During his internship he supported his team with the validation of the windows* 8 tablet platform. He also developed several sample windows* 8 applications. Cristiano has returned to school as a full time student to complete his bachelor's degree in computer science. He took up a full time position with Intel and will be joining soon after completing his degree.

Notices

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm

Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations, and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products.

Any software source code reprinted in this document is furnished under a software license and may only be used or copied in accordance with the terms of that license.

Intel and the Intel logo are trademarks of Intel Corporation in the US and/or other countries.

Copyright © 2012 Intel Corporation. All rights reserved.

*Other names and brands may be claimed as the property of others.

For more complete information about compiler optimizations, see our Optimization Notice.
Categories: