Flash production online video conferencing program
Package {
Import flash. display. Sprite;
Import flash.net. NetConnection;
Import flash.net. NetStream;
Import flash. events. NetStatusEvent;
Import flash. media. Video;
Import flash. media. Camera;
Import flash. events. ActivityEvent;
Public class videoChat extends Sprite
{
[SWF (backgroundColor = '0xdedede', frameRate = '000000', width = '000000', height = '000000')] // Set the swf parameter
Private var conn: connFcs, camera: Camera, videoIn: Video, outStream: NetStream, inStream: NetStream;
Public function videoChat ()
{
Var url: http://www.111cn.net/flash_a/112/String= "rtmp:/test_chat"; // connection address
Var conn: connFcs = new connFcs (url); // establish a connection. This class is located at the bottom of
This. conn = conn;
Conn. addEventListener (NetStatusEvent. NET_STATUS, NetStatusEventHandel); // monitor the connection status
}
Private function NetStatusEventHandel (event: NetStatusEvent): void
{
Trace (event.info. code );
If (event.info. code = "NetConnection. Connect. Success") // if the connection is successful
{
Init (); // Initialization
PublishStream (); // publish a video
}
}
Private function publishStream (): void
{
OutStream = new NetStream (conn );
OutStream. publish ("test", "record"); // The publish parameter. "test" indicates the Video name and "record" indicates the video to be saved. If it is not saved, use "live".
OutStream. attachCamera (camera );
InVideo ();
}
Private function inVideo (): void
{// Receives the video
InStream = new NetStream (conn );
InStream. play ("test ");
VideoIn. attachNetStream (inStream );
}
Private function init (): void
{
VideoIn = new Video (); // add a Video to receive
AddChild (videoIn );
Camera = Camera. getCamera (); // Get the camera
If (camera! = Null) // if there is a camera, add a video to the display
{
Camera. addEventListener (ActivityEvent. ACTIVITY, activityHandler );
Var video: Video = new Video (camera. width * 2, camera. height * 2 );
Video. x = camera. width;
Video. y = camera. height;
Video. attachCamera (camera );
AddChild (video );
} Else {trace ("you need camera! ");}
}
Private function activityHandler (event: ActivityEvent): void
{
Trace ('activityhandler' + event );
}
}
}
Import flash.net. NetConnection;
Import flash.net. ObjectEncoding;
Class connFcs extends NetConnection
{
Private var url: http://www.111cn.net/flash_a/112/String
Public function connFcs (url: http://www.111cn.net/flash_a/112/String)
{
ObjectEncoding = ObjectEncoding. AMF0; // set this parameter when connecting to the fcs.
This. url = url;
Connect (url); // start the connection
}
}
Flash production online video conferencing program