FMS入门----播放视频流

来源:互联网 发布:遥感影像处理 知乎 编辑:程序博客网 时间:2024/05/29 03:06

<?xmlversion="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="
http://ns.adobe.com/mxml/2009"
     xmlns:s="library://ns.adobe.com/flex/spark"
     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"minHeight="600"
     creationComplete="ConnFMS()">
 <s:layout>
  <s:BasicLayout/>
 </s:layout>

 

 <fx:Declarations>
  <!--将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <fx:Scriptsource="test/streams.as">
 </fx:Script>
 <s:Panel x="327" y="50"width="519" height="515" title="链接中..."id="mypanel">
  <s:Buttonx="410" y="451" label="按钮" id="start"click="start_clickHandler(event)"/>
  <s:VideoDisplayx="6" y="5" width="501" height="362"id="myvid"/>
 </s:Panel>
</s:Application>

 

 

importflash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import mx.controls.*;
import flash.display.*;
import flash.net.*;

private varnc:NetConnection;
private var ns:NetStream;
private var video:Video;

public functionConnFMS():void

 nc = new NetConnection();
 nc.connect("rtmp://localhost/streams");
 nc.client=this;
 nc.addEventListener(NetStatusEvent.NET_STATUS,onStatusHandler);
}

private functiononStatusHandler(evt:NetStatusEvent):void
{
 if(evt.info.code=="NetConnection.Connect.Success")
 {
  mypanel.title="成功连接FMS服务器!";
 }else{
  mypanel.title=evt.info.code;
 }
}

 
private function start_clickHandler(event:MouseEvent):void
{
  ns=new NetStream(nc);
  ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusHandler);
  //ns.client=newCustomClient();
  video=new Video();
  video.attachNetStream(ns);
  ns.play("aaa",0);
  myvid.addChild(video);
}


原创粉丝点击