Chapter 33. Capturing Sound and Video

FEATURED CLASSES

  • flash.media.Camera

  • flash.media.Microphone

Too often, Flash Player is viewed strictly as a way to show things to the user. But Flash Player can also be a tool that the user can communicate with. A computer's inputs aren't limited to just a mouse and keyboard: most computers have microphones or cameras attached or integrated. ActionScript can use these peripherals with the Camera and Microphone classes. Video and audio streams can be saved using Flash Media Server or a compatible product, or they can be analyzed and recorded locally.

Video Input Using a Camera

To capture video, you first have to retrieve the appropriate Camera object. The user's operating system is responsible for reporting compatible video devices to Flash Player; not just webcams, but digital video cameras, and maybe the occasional TV tuner card, may be used as a video source. I'll generically refer to all of these as a "camera" for simplicity's sake. Also, it's quite possible that the user has no compatible video device connected.

Retrieving a Camera Object

Each accessible video device on the user's system appears as an instance of Camera, so you don't create a Camera instance yourself, but retrieve the proper one.

To get a single Camera object, call the static method Camera.getCamera(). The method takes the name of the camera you'd like to connect to, optionally. Leave the parameter out, and it returns the default camera (as best as Flash Player can tell which is ...

Get ActionScript 3.0 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.