http://www.cnblogs.com/beniao/category/190537.html
1.在帧上输入代码:
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.NetStatusEvent;
var nc:NetConnection = new NetConnection();
var ns:NetStream ;
var video:Video;
var customClient:CustomClient = new CustomClient();
nc.connect("rtmp://localhost/firstfmsapp");
nc.addEventListener(NetStatusEvent.NET_STATUS,onStatus);
function onStatus(e:NetStatusEvent):void{
trace(e.info.code);
if(e.info.code == "NetConnection.Connect.Success"){
ns = new NetStream(nc);
//下面一行貌似可以注释掉
// ns.addEventListener(NetStatusEvent.NET_STATUS,onStatus);
ns.client = customClient ;
video = new Video();
video.attachNetStream(ns);
ns.play("future",0);
addChild(video);
}
}
-----------------------------------------
因为要用到CustomClient类,其实这个类只是提供了 onMetaData(info:Object):void 和 onCuePoint(info:Object):void函数,在NetStream中用到,仅仅是定义就够了。
所以新建as文件 :
package
{
/**
* ...
* @author littlejoe
*/
public class CustomClient
{
public function CustomClient() {
}
public function onMetaData(info:Object):void
{
}
public function onCuePoint(info:Object):void
{
}
}
}
=================================
过程是:通过NetConnect连接到程序文件夹中,当连接成功后(e.info.code == "NetConnection.Connect.Success"),
把nc传给 定义的ns:NetStream,又要定义client。。。
ns播放指定的文件,应该是.flv文件不用表示后缀,其他需要‘
最后再把ns传给Video对象,通过video.attachNetStream(ns);
再显示在舞台上。
=========================
还要注意一个:
application--firstfmsapp--streams--_definst_,把flv等视频文件放在这文件夹下。