Video.attachVideo()

Availability

Usage

public attachVideo(source:Object) : Void

Parameters

source A NetStream or Camera object that is playing video or MP3 audio data or capturing video data, respectively. To drop the connection to the Video object, pass null for source.

Returns

Nothing.

Description

Method; specifies a video stream (source) to be displayed within the boundaries of the Video object on the Stage. The video stream is either a NetStream object being displayed by means of the NetStream.play() command (requires Flash Media Server), a Camera object, or null. If source is null, video is no longer played within the Video object.

You don't have to use this method if the FLV file contains only audio. The audio portion of an FLV fils is played automatically when the NetStream.play() command is issued.

If you want to control the audio, you can use MovieClip.attachAudio() to route the audio to a movie clip; you can then create a Sound object to control some aspects of the audio. For more information, see MovieClip.attachAudio().

Example

The following example plays live video locally, without the need for Flash Media Server:

var active_cam:Camera = Camera.get();
my_video.attachVideo(active_cam); // my_video is a Video object on the Stage.

The following example shows how to publish and record a video, and then play it back.

/* This script publishes and records video.
The recorded file will be named "allAboutMe.flv". */
var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://localhost/allAboutMe/mySpeech");
var publish_ns:NetStream = new NetStream(my_nc);
publish_ns.publish("allAboutMe", "record");
publish_ns.attachVideo(Camera.get());

/* This script plays the recorded file.
Note that no publishing stream is required to play a recorded file. */
var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://localhost/allAboutMe/mySpeech");
var subscribe_ns:NetStream = new NetStream(my_nc);
subscribe_ns.play("allAboutMe");
my_video.attachVideo(subscribe_ns);    // my_video is a Video object on the Stage.

See also

Camera class, NetStream.play(), NetStream.publish()