flex_播放视频_本地_与_FMS端
1 <?xml version="1.0" encoding="utf-8"?> 2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 3 xmlns:s="library://ns.adobe.com/flex/spark" 4 xmlns:mx="library://ns.adobe.com/flex/mx" 5 creationComplete="init();" 6 minWidth="955" 7 minHeight="600"> 8 9 <fx:Script> 10 <![CDATA[ 11 import flash.display.Sprite; 12 import flash.events.*; 13 import flash.media.Video; 14 import flash.net.NetConnection; 15 import flash.net.NetStream; 16 import flash.events.Event; 17 18 private var videoName:String = "sample"; 19 private var connection:NetConnection; 20 private var stream:NetStream; 21 22 23 protected function button1_clickHandler(event:MouseEvent):void 24 { 25 VideoExample(); 26 connection.connect(textdz.text); 27 } 28 29 protected function button2_clickHandler(event:MouseEvent):void 30 { 31 VideoExample(); 32 connection.connect(null); 33 } 34 35 public function onBWDone ():void{} 36 public function VideoExample():void 37 { 38 connection = new NetConnection(); 39 connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 40 connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 41 connection.client=this; 42 } 43 44 private function netStatusHandler(event:NetStatusEvent):void 45 { 46 switch (event.info.code) 47 { 48 case "NetConnection.Connect.Success": 49 connectStream(); 50 trace("NetConnection.Connect.Success : " + videoName); 51 break; 52 case "NetStream.Play.StreamNotFound": 53 trace("Unable to locate video: " + videoName); 54 break; 55 } 56 } 57 58 private function connectStream():void 59 { 60 stream = new NetStream(connection); 61 stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 62 stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 63 64 stream.client = {}; 65 stream.bufferTime = 0 ; 66 stream.play(texturl.text); 67 68 var video:Video = new Video() ; 69 video.smoothing = true ; 70 video.width = 480 ; 71 video.height = 290 ; 72 video.attachNetStream(stream); 73 sprct.addChild(video); 74 75 } 76 77 private function securityErrorHandler(event:SecurityErrorEvent):void 78 { 79 trace("securityErrorHandler: " + event); 80 } 81 82 private function asyncErrorHandler(event:AsyncErrorEvent):void 83 { 84 trace("asyncErrorHandler: " + event); 85 } 86 87 ]]> 88 </fx:Script> 89 90 <s:Label x="21" y="26" text="地址:" verticalAlign="middle"/> 91 <s:TextInput id="textdz" x="21" y="46" width="365" text="rtmp://localhost/vod"/> 92 <s:TextInput id="texturl" x="19" y="83" width="365" text="../videos/liuhan_test.f4v"/> 93 94 95 <s:Button x="18" y="118" label="开始_FMS" click="button1_clickHandler(event)"/> 96 <s:Button x="116" y="118" width="79" label="本地视屏" click="button2_clickHandler(event)"/> 97 98 <s:Scroller x="116" y="152" width="637" height="355" > 99 <s:VGroup id="VG" width="100%" height="100%" > 100 <s:VideoDisplay id="sprct" width="600" height="300" scaleMode="none"/> 101 </s:VGroup> 102 </s:Scroller> 103 104 105 106 </s:Application>