package
{
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.SyncEvent;
/**
* ...
* @author chb
*/
public class videoExample extends Sprite
{
/**
* ...
* 构造函数
*/
public function videoExample():void
{
trace("进入了构造函数");
setMain();
}
/**
* ...
* 主函数
*/
public function setMain():void
{
//创建远程连接对象
var nc:NetConnection = new NetConnection();
nc.connect(null);
//创建视频流
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
//http://124.42.1.100/nn1.flv
ns.play("http://124.42.1.100/nn1.flv");
//创建视频对象
var vid:Video=new Video(550,400);
vid.smoothing=true;
vid.attachNetStream(ns);
//把视频对象添加到舞台
stage.addChild(vid);
}
public function asyncErrorHandler(e:AsyncErrorEvent):void
{
trace("连接出现错误");
}
}
}