flex_播放视频_本地_与_FMS端

时间:2021-08-02 04:13:37
 <?xml version="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"
creationComplete="init();"
minWidth="955"
minHeight="600"> <fx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event; private var videoName:String = "sample";
private var connection:NetConnection;
private var stream:NetStream; protected function button1_clickHandler(event:MouseEvent):void
{
VideoExample();
connection.connect(textdz.text);
} protected function button2_clickHandler(event:MouseEvent):void
{
VideoExample();
connection.connect(null);
} public function onBWDone ():void{}
public function VideoExample():void
{
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.client=this;
} private function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
connectStream();
trace("NetConnection.Connect.Success : " + videoName);
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoName);
break;
}
} private function connectStream():void
{
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); stream.client = {};
stream.bufferTime = 0 ;
stream.play(texturl.text); var video:Video = new Video() ;
video.smoothing = true ;
video.width = 480 ;
video.height = 290 ;
video.attachNetStream(stream);
sprct.addChild(video); } private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
} private function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace("asyncErrorHandler: " + event);
} ]]>
</fx:Script> <s:Label x="21" y="26" text="地址:" verticalAlign="middle"/>
<s:TextInput id="textdz" x="21" y="46" width="365" text="rtmp://localhost/vod"/>
<s:TextInput id="texturl" x="19" y="83" width="365" text="../videos/liuhan_test.f4v"/> <s:Button x="18" y="118" label="开始_FMS" click="button1_clickHandler(event)"/>
<s:Button x="116" y="118" width="79" label="本地视屏" click="button2_clickHandler(event)"/> <s:Scroller x="116" y="152" width="637" height="355" >
<s:VGroup id="VG" width="100%" height="100%" >
<s:VideoDisplay id="sprct" width="600" height="300" scaleMode="none"/>
</s:VGroup>
</s:Scroller> </s:Application>