[Flex]两个视频netstream实现分段连续加载播放代码示例
flex两个netstream实现视频分段加载播放,flv分段连播,视频连播,flex与netstream
flex两个netstream实现视频分段加载播放
- <?xml version="1.0" encoding="utf-8"?>
- <!-- http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/ -->
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- viewSourceURL="srcview/index.html" xmlns:local="*"
- initialize="init();">
- <mx:Script>
- <![CDATA[
- private var urlArr:Array=["http://221.122.36.143/oa/video/1.flv", "http://221.122.36.143/oa/video/2.flv", "http://221.122.36.143/oa/video/p2.mp4"];
- public function init():void{
- myVideo.urlArr = urlArr;
- }
- ]]>
- </mx:Script>
- <local:mVideo id="myVideo"/>
- </mx:Application>
- 第二个文件:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Panel
- xmlns:mx="http://www.adobe.com/2006/mxml"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- private var nc:NetConnection;
- private var ns:NetStream;
- private var nc2:NetConnection;
- private var ns2:NetStream;
- private var video:Video;
- [Bindable]
- public var urlArr:Array=null;
- private var count:int=0;
- private var finished1:int=1; //1:播放正在进行;0:播放结束
- private var finished2:int=0; //1:播放正在进行;0:播放结束
- private function init():void
- {
- var nsClient:Object={};
- nc=new NetConnection();
- nc.connect(null);
- ns=new NetStream(nc);
- ns.play(urlArr[count]);
- ns.client=nsClient;
- ns.addEventListener(NetStatusEvent.NET_STATUS, myTest1);
- video=new Video();
- video.name="video1";
- video.width=uic.width;
- video.height=uic.height;
- video.attachNetStream(ns);
- if (uic.getChildByName("video1") != null)
- {
- uic.removeChild(uic.getChildByName("video1"));
- }
- count++;
- }
- private function init2():void
- {
- var nsClient:Object={};
- nc2=new NetConnection();
- nc2.connect(null);
- ns2=new NetStream(nc2);
- ns2.play(urlArr[count]);
- ns2.client=nsClient;
- ns2.addEventListener(NetStatusEvent.NET_STATUS, myTest2);
- video=new Video();
- video.name="video2";
- video.width=uic.width;
- video.height=uic.height;
- video.attachNetStream(ns2);
- if (uic.getChildByName("video2") != null)
- {
- uic.removeChild(uic.getChildByName("video2"));
- }
- count++;
- }
- private function myTest1(event:NetStatusEvent):void
- {
- trace("count1==>>" + count);
- trace("count1 onStatus:" + event.info.code);
- if (event.info.code == "NetStream.Buffer.Full")
- {
- if (count == 1)
- {
- uic.addChild(video);
- init2();
- }
- if (finished2 == 1)
- {
- ns.seek(0);
- ns.pause();
- }
- }
- else if (event.info.code == "NetStream.Play.Stop")
- {
- finished1=0;
- finished2=1;
- uic.addChild(video);
- ns2.togglePause();
- if (count <= urlArr.length)
- {
- init();
- }
- }
- }
- private function myTest2(event:NetStatusEvent):void
- {
- trace("count2==>>" + count);
- trace("count2 onStatus:" + event.info.code);
- if (event.info.code == "NetStream.Buffer.Full")
- {
- if (finished1 == 1)
- {
- ns2.seek(0);
- ns2.pause();
- }
- }
- else if (event.info.code == "NetStream.Play.Stop")
- {
- finished2=0;
- finished1=1;
- uic.addChild(video);
- ns.togglePause();
- if (count <= urlArr.length)
- {
- init2();
- }
- }
- }
- ]]>
- </mx:Script>
- <mx:VideoDisplay id="uic"
- width="550"
- height="450"/>
- <mx:ControlBar>
- <mx:Button label="Play/Pause"
- click="ns.togglePause();"/>
- <mx:Button label="Rewind"
- click="ns.seek(0); ns.pause();"/>
- </mx:ControlBar>
- </mx:Panel>
热门文章推荐
- 纯HLS(m3u8)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...