Package | flash.media |
Class | public final class Camera |
Inheritance | Camera EventDispatcher Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
A Camera instance captures video in landscape aspect ratio. On devices that can change the screen orientation, such as mobile phones, a Video object attached to the camera will only show upright video in a landscape-aspect orientation. Thus, mobile apps should use a landscape orientation when displaying video and should not auto-rotate.
On iOS, the video from the front camera is mirrored. On Android, it is not.
On mobile devices with an autofocus camera, autofocus is enabled automatically. If the camera does not support continuous autofocus,
and many mobile device cameras do not, then the camera is focused when the Camera object is attached to a video stream and whenever
the setMode()
method is called. On desktop computers, autofocus behavior is dependent on the camera driver and settings.
In an AIR application on Android and iOS, the camera does not capture video while an AIR app is not the active, foreground application. In addition, streaming connections can be lost when the application is in the background. On iOS, the camera video cannot be displayed when an application uses the GPU rendering mode. The camera video can still be streamed to a server.
AIR profile support: This feature is not
supported on AIR for TV devices. See
AIR Profile Support for more information regarding API support across multiple profiles.
Note that for AIR for TV devices, Camera.isSupported
is true
but
Camera.getCamera()
always returns null
. Camera access is not supported
in mobile browsers.
For information about capturing audio, see the Microphone class.
Important: The runtime displays a Privacy dialog box that lets the user choose whether to allow or deny access to the camera. Make sure your application window size is at least 215 x 138 pixels; this is the minimum size required to display the dialog box.
To create or reference a Camera object, use the getCamera()
method.
More examples
Verifying that cameras are installed
Detecting permissions for camera access
Maximizing camera video quality
Monitoring camera status
Learn more
Understanding video formats
Flash Player and AIR compatibility with encoded video files
Understanding the Adobe F4V and FLV video file formats
Advanced topics for video files
Video example: Video Jukebox
Understanding the Camera class
Displaying camera content on screen
Designing your camera application
Cristophe Coenraets: Video Chat for Android in 30 Lines of Code
Michael Chaize: Android, AIR, and the Camera
Related API Elements
Property | Defined By | ||
---|---|---|---|
activityLevel : Number [read-only]
The amount of motion the camera is detecting. | Camera | ||
bandwidth : int [read-only]
The maximum amount of bandwidth the current outgoing video feed can use, in bytes. | Camera | ||
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
currentFPS : Number [read-only]
The rate at which the camera is capturing data, in frames per second. | Camera | ||
fps : Number [read-only]
The maximum rate at which the camera can capture data, in frames per second. | Camera | ||
height : int [read-only]
The current capture height, in pixels. | Camera | ||
index : int [read-only]
A zero-based index that specifies the position of the camera in
the Camera.names array, which lists all available cameras. | Camera | ||
isSupported : Boolean [static] [read-only]
The isSupported property is set to true if the
Camera class is supported on the current platform, otherwise it is
set to false. | Camera | ||
keyFrameInterval : int [read-only]
The number of video frames transmitted in full (called keyframes)
instead of being interpolated by the video compression algorithm. | Camera | ||
loopback : Boolean [read-only]
Indicates whether a local view of what the camera is capturing is compressed
and decompressed (true), as it would be for live transmission using
Flash Media Server, or uncompressed (false). | Camera | ||
motionLevel : int [read-only]
The amount of motion required to invoke the activity event. | Camera | ||
motionTimeout : int [read-only]
The number of milliseconds between the time the camera stops detecting motion and the time the activity event is invoked. | Camera | ||
muted : Boolean [read-only]
A Boolean value indicating whether the user has denied access to the camera
(true) or allowed access (false) in the Flash Player Privacy dialog box. | Camera | ||
name : String [read-only]
The name of the current camera, as returned by the camera hardware. | Camera | ||
names : Array [static] [read-only]
An array of strings containing the names of all available cameras. | Camera | ||
permissionStatus : String [static] [read-only]
Determine whether the application has been granted the permission to use camera. | Camera | ||
position : String [read-only]
Specifies the side of a device on which the camera is located. | Camera | ||
quality : int [read-only]
The required level of picture quality, as determined by the amount of compression being applied to each video
frame. | Camera | ||
width : int [read-only]
The current capture width, in pixels. | Camera |
Method | Defined By | ||
---|---|---|---|
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Fills a byte array from a rectangular region of pixel data
Writes an unsigned integer (a 32-bit unmultiplied pixel value)
for each pixel into the byte array. | Camera | ||
Fills a vector from a rectangular region of pixel data. | Camera | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Copies the last frame to a bitmap. | Camera | ||
[static]
Returns a reference to a Camera object for capturing video. | Camera | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Requests camera permission for the application. | Camera | ||
Specifies which video frames are transmitted in full (called keyframes)
instead of being interpolated by the video compression algorithm. | Camera | ||
Specifies whether to use a compressed video stream for a local view of the camera. | Camera | ||
Sets the camera capture mode to the native mode that best meets the specified requirements. | Camera | ||
Specifies how much motion is required to dispatch the activity event. | Camera | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Sets the maximum amount of bandwidth per second or the required picture quality
of the current outgoing video feed. | Camera | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | |||
Dispatched when a camera begins or ends a session. | Camera | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher | |||
Dispatched when the application requests permission to use camera on the device. | Camera | |||
Dispatched when a camera reports its status. | Camera | |||
Dispatched after a new camera frame is processed by the runtime and is available to be copied. | Camera |
activityLevel | property |
activityLevel:Number
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The amount of motion the camera is detecting. Values range from 0 (no motion is being detected) to
100 (a large amount of motion is being detected). The value of this property can help you determine if you need to pass a setting
to the setMotionLevel()
method.
If the camera is available but is not yet being used because the
Video.attachCamera()
method has not been called, this property
is set to -1.
If you are streaming only uncompressed local video, this property is set only if you have assigned a function to the event handler. Otherwise, it is undefined.
Implementation
public function get activityLevel():Number
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
bandwidth | property |
bandwidth:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The maximum amount of bandwidth the current outgoing video feed can use, in bytes. A value of 0 means the feed can use as much bandwidth as needed to maintain the desired frame quality.
To set this property, use the setQuality()
method.
Implementation
public function get bandwidth():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
currentFPS | property |
currentFPS:Number
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The rate at which the camera is capturing data, in frames per second.
This property cannot be set; however, you can use the setMode()
method
to set a related property—fps
—which specifies the maximum
frame rate at which you would like the camera to capture data.
Implementation
public function get currentFPS():Number
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
fps | property |
fps:Number
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The maximum rate at which the camera can capture data, in frames per second. The maximum rate possible depends on the capabilities of the camera; this frame rate may not be achieved.
- To set a desired value for this property, use the
setMode()
method. - To determine the rate at which the camera is currently capturing data, use the
currentFPS
property.
Implementation
public function get fps():Number
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
height | property |
height:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The current capture height, in pixels. To set a value for this property,
use the setMode()
method.
Implementation
public function get height():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
index | property |
index:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
A zero-based index that specifies the position of the camera in
the Camera.names
array, which lists all available cameras.
Implementation
public function get index():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
isSupported | property |
isSupported:Boolean
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 10.1, AIR 2 |
The isSupported
property is set to true
if the
Camera class is supported on the current platform, otherwise it is
set to false
.
Implementation
public static function get isSupported():Boolean
keyFrameInterval | property |
keyFrameInterval:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The number of video frames transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm. The default value is 15, which means that every 15th frame is a keyframe. A value of 1 means that every frame is a keyframe. The allowed values are 1 through 300.
Implementation
public function get keyFrameInterval():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
loopback | property |
loopback:Boolean
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Indicates whether a local view of what the camera is capturing is compressed
and decompressed (true
), as it would be for live transmission using
Flash Media Server, or uncompressed (false
). The default value is
false
.
Although a compressed stream is useful for testing, such as when previewing video quality settings, it has a significant processing cost. The local view is compressed, edited for transmission as it would be over a live connection, and then decompressed for local viewing.
To set this value, use Camera.setLoopback()
. To set the amount of
compression used when this property is true, use Camera.setQuality()
.
Implementation
public function get loopback():Boolean
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
motionLevel | property |
motionLevel:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The amount of motion required to invoke the activity
event. Acceptable values range from 0 to 100.
The default value is 50.
Video can be displayed regardless of the value of the motionLevel
property. For more information, see
setMotionLevel()
.
Implementation
public function get motionLevel():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
motionTimeout | property |
motionTimeout:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The number of milliseconds between the time the camera stops detecting motion and the time the activity
event is invoked. The
default value is 2000 (2 seconds).
To set this value, use setMotionLevel()
.
Implementation
public function get motionTimeout():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
muted | property |
muted:Boolean
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
A Boolean value indicating whether the user has denied access to the camera
(true
) or allowed access (false
) in the Flash Player Privacy dialog box.
When this value changes, the status
event is dispatched.
Implementation
public function get muted():Boolean
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
name | property |
name:String
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The name of the current camera, as returned by the camera hardware.
Implementation
public function get name():String
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
names | property |
names:Array
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
An array of strings containing the names of all available cameras.
Accessing this array does not display the Flash Player Privacy dialog box. This array
provides the zero-based index of each camera and the number of cameras on the system (by means of
names.length
).
Calling the names
property requires an extensive examination of the hardware.
In most cases, you can just use the default camera.
Implementation
public static function get names():Array
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
permissionStatus | property |
position | property |
position:String
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3.0 |
Specifies the side of a device on which the camera is located.
Use the position
property to determine whether a camera on a mobile device is
on the front or back face of the device. The following function checks every available camera until it finds
a camera with the desired position. If no camera has the desired position, then the default camera is returned.
function getCamera( position:String ):Camera { var camera:Camera; var cameraCount:uint = Camera.names.length; for ( var i:uint = 0; i < cameraCount; ++i ) { camera = Camera.getCamera( String(i) ); if ( camera.position == position ) return camera; } return Camera.getCamera();
On mobile devices the camera position is normally either CameraPosition.FRONT
or CameraPosition.BACK
.
If the position of the Camera cannot be determined then the position is reported as CameraPosition.UNKNOWN
.
On desktop platforms, the position is always CameraPosition.UNKNOWN
.
Constants for the valid values of this property are defined in the CameraPosition class
Implementation
public function get position():String
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
quality | property |
quality:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The required level of picture quality, as determined by the amount of compression being applied to each video frame. Acceptable quality values range from 1 (lowest quality, maximum compression) to 100 (highest quality, no compression). The default value is 0, which means that picture quality can vary as needed to avoid exceeding available bandwidth.
To set this property, use the setQuality()
method.
Implementation
public function get quality():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
width | property |
width:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
The current capture width, in pixels. To set a desired value for this property,
use the setMode()
method.
Implementation
public function get width():int
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
copyToByteArray | () | method |
public function copyToByteArray(rect:Rectangle, destination:ByteArray):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11.4, AIR 3.4 |
Fills a byte array from a rectangular region of pixel data
Writes an unsigned integer (a 32-bit unmultiplied pixel value) for each pixel into the byte array. The array is resized to the necessary number of bytes to hold all the pixels.
Parameters
rect:Rectangle — A rectangular area in the current BitmapData object.
| |
destination:ByteArray — A ByteArray representing the pixels in the given rectangle.
|
Throws
PermissionError — The application does not have permission to use camera.
| |
TypeError — The rect is null.
| |
TypeError — The destination is null
|
Related API Elements
copyToVector | () | method |
public function copyToVector(rect:Rectangle, destination:Vector.<uint>):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11.4, AIR 3.4 |
Fills a vector from a rectangular region of pixel data.
Writes an unsigned integer (a 32-bit unmultiplied pixel value) for each pixel into the vector. The vector is resized to the necessary number of entries to hold all the pixels.
Parameters
rect:Rectangle — A rectangular area in the current BitmapData object.
| |
destination:Vector.<uint> — A Vector.<uint> representing the pixels in the given rectangle.
|
Throws
PermissionError — The application does not have permission to use camera.
| |
TypeError — The rect is null.
| |
TypeError — The destination is null
|
Related API Elements
drawToBitmapData | () | method |
public function drawToBitmapData(destination:BitmapData):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11.4, AIR 3.4 |
Copies the last frame to a bitmap.
This method copies the contents of the last frame to a BitmapData instance.
Parameters
destination:BitmapData — A BitmapData instance object to contain the last frame.
|
Throws
ArgumentError — kInvalidBitmapDataError if destination is too small
|
Related API Elements
getCamera | () | method |
public static function getCamera(name:String = null):Camera
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Returns a reference to a Camera object for capturing video. To begin capturing
the video, you must attach the Camera object to a Video object (see Video.attachCamera()
). To transmit video to Flash Media Server, call NetStream.attachCamera()
to attach the Camera object to a NetStream object.
Multiple calls to the getCamera()
method reference the same camera driver.
Thus, if your code contains code like firstCam:Camera = getCamera()
and secondCam:Camera = getCamera()
,
both firstCam
and secondCam
reference the same camera,
which is the user's default camera.
On mobile devices with a both a front- and a rear-facing camera, you can only capture video from one camera at a time.
In general, you shouldn't pass a value for the name
parameter; simply use
getCamera()
to return a reference to the default camera. By means of the Camera
settings panel (discussed later in this section), the user can specify the default camera
to use.
You can't use ActionScript to set a user's Allow or Deny permission setting
for access to the camera, but you can display the Adobe Flash Player Settings camera
setting dialog box where the user can set the camera permission. When a SWF file using
the attachCamera()
method tries to
attach the camera returned by the getCamera()
method to a Video or
NetStream object, Flash Player displays a dialog box that lets the user choose
to allow or deny access to the camera. (Make sure your application window size is at least
215 x 138 pixels; this is the minimum size Flash Player requires to display the dialog box.)
When the user responds to the camera setting dialog box, Flash Player returns an
information object in the status
event that indicates the user's response:
Camera.Muted
indicates
the user denied access to a camera; Camera.Unmuted
indicates the user allowed access
to a camera. To determine whether the user has denied or allowed access to the camera without
handling the status
event, use the muted
property.
In Flash Player, the user can specify permanent privacy settings for a particular domain by right-clicking (Windows and Linux) or Control-clicking (Macintosh) while a SWF file is playing, selecting Settings, opening the Privacy dialog, and selecting Remember. If the user selects Remember, Flash Player no longer asks the user whether to allow or deny SWF files from this domain access to your camera.
Note: The attachCamera()
method will not invoke the dialog box
to Allow or Deny access to the camera if the user has denied access by selecting Remember
in the Flash Player Settings dialog box. In this case, you can prompt the user to change the
Allow or Deny setting by displaying the Flash Player Privacy panel for the user
using Security.showSettings(SecurityPanel.PRIVACY)
.
If getCamera()
returns null
, either the camera is in use by another
application, or there are no cameras installed on the system. To determine whether any cameras
are installed, use the names.length
property. To display the Flash Player Camera Settings panel,
which lets the user choose the camera to be referenced by getCamera()
, use
Security.showSettings(SecurityPanel.CAMERA)
.
Scanning the hardware for cameras takes time. When the runtime finds at least one camera,
the hardware is not scanned again for the lifetime of the player instance. However, if
the runtime doesn't find any cameras, it will scan each time getCamera
is called.
This is helpful if the camera is present but is disabled; if your SWF file provides a
Try Again button that calls getCamera
, Flash Player can find the camera without the
user having to restart the SWF file.
Parameters
name:String (default = null ) — Specifies which camera to get, as determined from the array
returned by the names property. For most applications, get the default camera
by omitting this parameter. To specify a value for this parameter, use the string representation
of the zero-based index position within the Camera.names array. For example, to specify the third
camera in the array, use Camera.getCamera("2") .
|
Camera — If the name parameter is not specified, this method returns a reference
to the default camera or, if it is in use by another application, to the first
available camera. (If there is more than one camera installed, the user may specify
the default camera in the Flash Player Camera Settings panel.) If no cameras are available
or installed, the method returns null .
|
Events
status: — Dispatched when a camera reports its status.
Before accessing a camera, Flash Player displays a Privacy dialog box to let users
allow or deny access to their camera. If the value of the code property is "Camera.Muted" ,
the user has refused to allow the SWF file access to the user's camera.
If the value of the code property is "Camera.Unmuted" ,
the user has allowed the SWF file access to the user's camera.
|
Related API Elements
Example ( How to use this example )
The Camera.getCamera()
method returns a reference to a camera object, or returns null if
no camera is available or installed. The if statement checks whether the camera was found and whether
the user allowed access to the camera. If the user denied access, the muted
property is set to true
.
Usually, when the attachCamera()
method is invoked, a dialog box appears and prompts the
user to allow or deny Flash Player access to the camera. However, if the user denied access
and selected the Remember
option, the dialog box does not appear and nothing displays.
To make sure the user has the option to allow access to the camera, the myTextField
text field
instructs the user to click the text field to invoke the Flash Player Settings dialog box.
The clickHandler()
method calls Security.showSettings()
method, which
displays the PRIVACY
panel of the Settings dialog box. If the user allows access,
the StatusEvent.STATUS
event is dispatched and the value of the event's code
property is set to Camera.Unmuted
. (The camera object's mute
property is also
set to false
.)
The statusHandler()
method, added to listen to the status change of the user's setting,
invokes the connectCamera()
method, if the user allows access. The connectCamera()
method instantiates a video object with the captured stream's width and height. To display the
camera's captured video, the reference to the video stream is attached to the video object, and the video
object is added to the display list.
A Timer object also is started. Every second, a Timer object's timer event is dispatched and the
timerHandler()
method is invoked. The timerHandler()
method is displayed and updates
a number of properties of the Camera object.
Note: For this example, the only property that changes
is the currentFPS
property.
package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.StatusEvent; import flash.events.MouseEvent; import flash.system.SecurityPanel; import flash.system.Security; public class Camera_getCameraExample extends Sprite { private var myTextField:TextField; private var cam:Camera; private var t:Timer = new Timer(1000); public function Camera_getCameraExample() { myTextField = new TextField(); myTextField.x = 10; myTextField.y = 10; myTextField.background = true; myTextField.selectable = false; myTextField.autoSize = TextFieldAutoSize.LEFT; if (Camera.isSupported) { cam = Camera.getCamera(); if (!cam) { myTextField.text = "No camera is installed."; } else if (cam.muted) { myTextField.text = "To enable the use of the camera,\n" + "please click on this text field.\n" + "When the Flash Player Settings dialog appears,\n" + "make sure to select the Allow radio button\n" + "to grant access to your camera."; myTextField.addEventListener(MouseEvent.CLICK, clickHandler); }else { myTextField.text = "Connecting"; connectCamera(); } addChild(myTextField); t.addEventListener(TimerEvent.TIMER, timerHandler); }else { myTextField.text = "The Camera class is not supported on this device."; } } private function clickHandler(e:MouseEvent):void { Security.showSettings(SecurityPanel.PRIVACY); cam.addEventListener(StatusEvent.STATUS, statusHandler); myTextField.removeEventListener(MouseEvent.CLICK, clickHandler); } private function statusHandler(event:StatusEvent):void { if (event.code == "Camera.Unmuted") { connectCamera(); cam.removeEventListener(StatusEvent.STATUS, statusHandler); } } private function connectCamera():void { var vid:Video = new Video(cam.width, cam.height); vid.x = 10; vid.y = 10; vid.attachCamera(cam); addChild(vid); t.start(); } private function timerHandler(event:TimerEvent):void { myTextField.y = cam.height + 20; myTextField.text = ""; myTextField.appendText("bandwidth: " + cam.bandwidth + "\n"); myTextField.appendText("currentFPS: " + Math.round(cam.currentFPS) + "\n"); myTextField.appendText("fps: " + cam.fps + "\n"); myTextField.appendText("keyFrameInterval: " + cam.keyFrameInterval + "\n"); } } }
requestPermission | () | method |
public function requestPermission():void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 24.0 |
Requests camera permission for the application.
Events
PermissionStatus: — dispatched when the requested permission is granted/denied by the user.
|
setKeyFrameInterval | () | method |
public function setKeyFrameInterval(keyFrameInterval:int):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Specifies which video frames are transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm. This method is applicable only if you are transmitting video using Flash Media Server.
The Flash Video compression algorithm compresses video by transmitting only what has changed since the last frame of the video; these portions are considered to be interpolated frames. Frames of a video can be interpolated according to the contents of the previous frame. A keyframe, however, is a video frame that is complete; it is not interpolated from prior frames.
To determine how to set a value for the keyFrameInterval
parameter,
consider both bandwidth use and video playback accessibility. For example,
specifying a higher value for keyFrameInterval
(sending keyframes less frequently)
reduces bandwidth use.
However, this may increase the amount of time required to position the playhead
at a particular point in the video; more prior video frames may have to be interpolated
before the video can resume.
Conversely, specifying a lower value for keyFrameInterval
(sending keyframes more frequently) increases bandwidth use because entire video frames
are transmitted more often, but may decrease the amount of time required to seek a
particular video frame within a recorded video.
Parameters
keyFrameInterval:int — A value that specifies which video frames are transmitted in full
(as keyframes) instead of being interpolated by the video compression algorithm.
A value of 1 means that every frame is a keyframe, a value of 3 means that every third frame
is a keyframe, and so on. Acceptable values are 1 through 48.
|
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
setLoopback | () | method |
public function setLoopback(compress:Boolean = false):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Specifies whether to use a compressed video stream for a local view of the camera.
This method is applicable only if you are transmitting video using Flash Media Server;
setting compress
to true
lets you see more precisely how the video
will appear to users when they view it in real time.
Although a compressed stream is useful for testing purposes, such as previewing video quality settings, it has a significant processing cost, because the local view is not simply compressed; it is compressed, edited for transmission as it would be over a live connection, and then decompressed for local viewing.
To set the amount of compression used when you set compress
to true
,
use Camera.setQuality()
.
Parameters
compress:Boolean (default = false ) — Specifies whether to use a compressed video stream (true )
or an uncompressed stream (false ) for a local view of what the camera
is receiving.
|
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
setMode | () | method |
public function setMode(width:int, height:int, fps:Number, favorArea:Boolean = true):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Sets the camera capture mode to the native mode that best meets the specified requirements. If the camera does not have a native mode that matches all the parameters you pass, the runtime selects a capture mode that most closely synthesizes the requested mode. This manipulation may involve cropping the image and dropping frames.
By default, the runtime drops frames as needed to maintain image size. To minimize the number
of dropped frames, even if this means reducing the size of the image, pass false
for the favorArea
parameter.
When choosing a native mode, the runtime tries to maintain the requested aspect ratio
whenever possible. For example, if you issue the command myCam.setMode(400, 400, 30)
,
and the maximum width and height values available on the camera are 320 and 288, the runtime sets
both the width and height at 288; by setting these properties to the same value, the runtime
maintains the 1:1 aspect ratio you requested.
To determine the values assigned to these properties after the runtime selects the mode
that most closely matches your requested values, use the width
, height
,
and fps
properties.
If you are using Flash Media Server, you can also capture single frames or create time-lapse
photography. For more information, see NetStream.attachCamera()
.
Parameters
width:int — The requested capture width, in pixels. The default value is 160.
| |
height:int — The requested capture height, in pixels. The default value is 120.
| |
fps:Number — The requested rate at which the camera should capture data, in frames per second.
The default value is 15.
| |
favorArea:Boolean (default = true ) — Specifies whether to manipulate the width, height, and frame rate if
the camera does not have a native mode that meets the specified requirements.
The default value is true , which means that maintaining capture size
is favored; using this parameter selects the mode that most closely matches
width and height values, even if doing so adversely affects
performance by reducing the frame rate. To maximize frame rate at the expense
of camera height and width, pass false for the favorArea parameter.
|
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
Example ( How to use this example )
The Stage is set so it does not scale. The Camera.getCamera()
method
returns a reference to a camera object, or returns null if no camera is available or installed.
If a camera exists, the connectCamera()
method is called.
The connectCamera()
method instantiates a video object. To
display the camera's captured video, the reference to the video stream is attached
to the video object, and the video object is added to the display list. An event listener
also is set for a MouseEvent.CLICK
event. After the user clicks on the Stage,
the clickHandler()
method is invoked. The method checks the width of the
captured video and sets the camera capture mode's width, height, and the frame per second
request rate. In order for these setting to take effect, the video object must be removed
and re-created. The video's width and height also must be set to the camera object's width
and height.
package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.events.MouseEvent; import flash.display.StageScaleMode; public class Camera_setModeExample extends Sprite { private var cam:Camera; private var vid:Video; public function Camera_setModeExample() { stage.scaleMode = StageScaleMode.NO_SCALE; cam = Camera.getCamera(); if (!cam) { trace("No camera is installed."); }else { connectCamera(); } } private function connectCamera():void { vid = new Video(); vid.width = cam.width; vid.height = cam.height; vid.attachCamera(cam); addChild(vid); stage.addEventListener(MouseEvent.CLICK, clickHandler); } private function clickHandler(e:MouseEvent):void { switch (cam.width) { case 160: cam.setMode(320, 240, 10); break; case 320: cam.setMode(640, 480, 5); break; default: cam.setMode(160, 120, 15); break; } removeChild(vid); connectCamera(); } } }
setMotionLevel | () | method |
public function setMotionLevel(motionLevel:int, timeout:int = 2000):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Specifies how much motion is required to dispatch the activity
event.
Optionally sets the number of milliseconds that must elapse without activity before
the runtime considers motion to have stopped and dispatches the event.
Note: Video can be displayed regardless of the value of the
motionLevel
parameter. This parameter determines only when and under
what circumstances the event is dispatched—not whether video is actually being
captured or displayed.
To prevent the camera from detecting motion at all, pass a value of 100 for the
motionLevel
parameter; the activity
event is never dispatched.
(You would probably use this value only for testing purposes—for example, to
temporarily disable any handlers that would normally be triggered when the event is dispatched.)
To determine the amount of motion the camera is currently detecting, use the
activityLevel
property.
Motion sensitivity values correspond directly to activity values.
Complete lack of motion is an activity value of 0. Constant motion is an activity value of 100.
Your activity value is less than your motion sensitivity value when you're not moving;
when you are moving, activity values frequently exceed your motion sensitivity value.
This method is similar in purpose to the Microphone.setSilenceLevel()
method;
both methods are used to specify when the activity
event
should be dispatched. However, these methods have a significantly different impact
on publishing streams:
Microphone.setSilenceLevel()
is designed to optimize bandwidth. When an audio stream is considered silent, no audio data is sent. Instead, a single message is sent, indicating that silence has started.Camera.setMotionLevel()
is designed to detect motion and does not affect bandwidth usage. Even if a video stream does not detect motion, video is still sent.
Parameters
motionLevel:int — Specifies the amount of motion required to dispatch the
activity event. Acceptable values range from 0 to 100. The default value is 50.
| |
timeout:int (default = 2000 ) — Specifies how many milliseconds must elapse without activity
before the runtime considers activity to have stopped and dispatches the activity event.
The default value is 2000 milliseconds (2 seconds).
|
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
Example ( How to use this example )
The Camera.getCamera()
method returns a reference to a camera object,
or returns null if no camera is available or installed. The if statement checks whether a camera
is available, and invokes the connectCamera()
method when it is available.
The connectCamera()
method instantiates a video object with the captured stream's
width and height. To display the camera's captured video, the reference to the
video stream is attached to the video object, and the video object is added to the display list.
(Usually, when the attachCamera()
method is invoked, a dialog box appears and
prompts the user to allow or deny Flash Player access to the camera. However, if the
user denied access and selected the Remember
option, the dialog box does not appear
and nothing is displayed. To make sure the user has the option to allow access to the camera, use the
system.Security.showSettings()
method to invoke the Flash Player
Settings dialog box.)
The setMotionLevel()
method sets the level of activity (amount of motion), before
the activity event is invoked, to five, for minimal motion. The time between when the camera stops
detecting motion and when the activity event is invoked, is set to 1 second (1000 millisecond). After 1 second
passes without activity or the level of activity reaches five, the ActivityEvent.ACTIVITY
event is dispatched and the activityHandler()
method is invoked. If the event
was triggered by the level of activity, the activating
property is set to
true
and a Timer object is started. Every second, a Timer object’s timer event
is dispatched and the timerHandler()
method is invoked, which displays the current
level of activity. (Although a level of five or larger triggers the timer, the displayed
current level of activity might be a smaller number.)
package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.ActivityEvent; public class Camera_setMotionLevelExample extends Sprite { private var myTextField:TextField; private var cam:Camera; private var t:Timer = new Timer(1000); public function Camera_setMotionLevelExample() { myTextField = new TextField(); myTextField.background = true; myTextField.selectable = false; myTextField.autoSize = TextFieldAutoSize.LEFT; cam = Camera.getCamera(); if (!cam) { myTextField.text = "No camera is installed."; }else { myTextField.text = "Waiting to connect."; connectCamera(); } addChild(myTextField); t.addEventListener(TimerEvent.TIMER, timerHandler); } private function connectCamera():void { var vid:Video = new Video(cam.width, cam.height); vid.x = 10; vid.y = 10; vid.attachCamera(cam); addChild(vid); cam.setMotionLevel(5, 1000); cam.addEventListener(ActivityEvent.ACTIVITY, activityHandler); } private function activityHandler(e:ActivityEvent):void { if (e.activating == true) { t.start(); } else { myTextField.text = "Everything is quiet."; t.stop(); } } private function timerHandler(event:TimerEvent):void { myTextField.x = 10; myTextField.y = cam.height + 20; myTextField.text = "There is some activity. Level: " + cam.activityLevel; } } }
setQuality | () | method |
public function setQuality(bandwidth:int, quality:int):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Sets the maximum amount of bandwidth per second or the required picture quality of the current outgoing video feed. This method is generally applicable only if you are transmitting video using Flash Media Server.
Use this method to specify which element of the outgoing video feed is more important to your application—bandwidth use or picture quality.
- To indicate that bandwidth use takes precedence, pass a value for
bandwidth
and 0 forquality
. The runtime transmits video at the highest quality possible within the specified bandwidth. If necessary, the runtime reduces picture quality to avoid exceeding the specified bandwidth. In general, as motion increases, quality decreases. - To indicate that quality takes precedence, pass 0 for
bandwidth
and a numeric value forquality
. The runtime uses as much bandwidth as required to maintain the specified quality. If necessary, the runtime reduces the frame rate to maintain picture quality. In general, as motion increases, bandwidth use also increases. - To specify that both bandwidth and quality are equally important, pass numeric values for both parameters. The runtime transmits video that achieves the specified quality and that doesn't exceed the specified bandwidth. If necessary, the runtime reduces the frame rate to maintain picture quality without exceeding the specified bandwidth.
Parameters
bandwidth:int — Specifies the maximum amount of bandwidth that the current outgoing video
feed can use, in bytes per second. To specify that the video can use as much bandwidth
as needed to maintain the value of quality , pass 0 for
bandwidth . The default value is 16384.
| |
quality:int — An integer that specifies the required level of picture quality,
as determined by the amount of compression being applied to each video frame.
Acceptable values range from 1 (lowest quality, maximum compression) to 100 (highest
quality, no compression). To specify that picture quality can vary as needed to avoid
exceeding bandwidth, pass 0 for quality .
|
Throws
PermissionError — The application does not have permission to use camera.
|
Related API Elements
activity | Event |
flash.events.ActivityEvent
property ActivityEvent.type =
flash.events.ActivityEvent.ACTIVITY
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when a camera begins or ends a session.
Call Camera.setMotionLevel()
to specify the amount of motion
required to trigger an activity
event with an activating
value of true
, or the time without activity
that must elapse before triggering an activity
event with an activating
value of false
.
ActivityEvent.ACTIVITY
constant defines the value of the type
property of an activity
event object.
This event has the following properties:
Property | Value |
---|---|
activating | true if the device is activating or false if it is deactivating. |
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The object beginning or ending a session, such as a Camera or Microphone object. |
permissionStatus | Event |
flash.events.PermissionEvent
property PermissionEvent.type =
flash.events.PermissionEvent.PERMISSION_STATUS
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 24.0 |
Dispatched when the application requests permission to use camera on the device.
Check the value of status
property to determine whether
the permission was granted or denied
Related API Elements
status | Event |
flash.events.StatusEvent
property StatusEvent.type =
flash.events.StatusEvent.STATUS
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR (unsupported) |
Dispatched when a camera reports its status.
Before accessing a camera, the runtime displays a Privacy dialog box to let users
allow or deny access to their camera. If the value of the code
property is "Camera.Muted"
,
the user has refused to allow the SWF file access to the user's camera.
If the value of the code
property is "Camera.Unmuted"
,
the user has allowed the SWF file access to the user's camera.
Note: This event is not dispatched on the AIR platform. It is used only in Flash Player.
Defines the value of thetype
property of a status
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
code | A description of the object's status. |
currentTarget | The object that is actively processing the Event object with an event listener. |
level | The category of the message, such as "status" , "warning" or "error" . |
target | The object reporting its status. |
Related API Elements
videoFrame | Event |
flash.events.Event
property Event.type =
flash.events.Event.VIDEO_FRAME
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11.4, AIR 3.4 |
Dispatched after a new camera frame is processed by the runtime and is available to be copied.
TheEvent.VIDEO_FRAME
constant defines the value of the
type
property of a videoFrame
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
target | The Camera object that dispatched this event. |
Related API Elements
activity
event is dispatched at the
start and end (if any) of the session and is captured by the activityHandler()
method, which prints out information about the event.
Note: A camera must be attached to your computer for this example to work correctly.
package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.*; import flash.media.Camera; import flash.media.Video; public class CameraExample extends Sprite { private var video:Video; public function CameraExample() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var camera:Camera = Camera.getCamera(); if (camera != null) { camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler); video = new Video(camera.width * 2, camera.height * 2); video.attachCamera(camera); addChild(video); } else { trace("You need a camera."); } } private function activityHandler(event:ActivityEvent):void { trace("activityHandler: " + event); } } }
Wed Nov 21 2018, 06:34 AM -08:00