Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" width="450" height="400"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- private var ns:NetStream;
- private var byteArray:ByteArray;
- public function init():void
- {
- var myVideo:Video = new Video(400,300);
- var nc:NetConnection = new NetConnection();
- nc.connect(null);
- var customClient:Object = new Object();
- ns = new NetStream(nc);
- ns.client = customClient;
- myVideo.attachNetStream(ns);
- ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- // important: play(null), otherwise exception
- ns.play(null);
- var fileName:String = "dummy-video.flv";
- byteArray = readFile(fileName);
- ns.appendBytes(byteArray);
- myUIComponent.addChild(myVideo);
- }
- private function netStatusHandler(event: NetStatusEvent): void
- {
- var code:String = event.info.code;
- trace("Code: "+code);
- switch (event.info.code)
- {
- case "NetStream.Seek.Notify":
- //seekPoint = event.info.seekPoint;
- trace("seeking to: ", seekPoint);
- seekPoint == 0 ? seekToBeginning() : seekToOffset(seekPoint);
- break;
- case "NetStream.Seek.Failed":
- trace("Seeking is Failed.");
- break;
- case "NetStream.Buffer.Full":
- break;
- case "NetStream.Buffer.Empty":
- ns.seek(0);
- //seekToBeginning();
- break;
- case "NetStream.Pause.Notify":
- break;
- case "NetStream.Unpause.Notify":
- break;
- }
- }
- private function readFile(fileName:String):ByteArray
- {
- var data:ByteArray = new ByteArray();
- var inFile:File = File.applicationDirectory; // source folder is application
- inFile = inFile.resolvePath(fileName); // name of file to read
- var inStream:FileStream = new FileStream();
- inStream.open(inFile, FileMode.READ);
- inStream.readBytes(data, 0, data.length);
- inStream.close();
- return data;
- }
- private function seekToOffset(seekPoint:Number):void
- {
- trace("Seeking Notify to Offset");
- //ns.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
- //ns.seek(seekPoint);
- }
- private function seekToBeginning():void
- {
- ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
- ns.appendBytes(byteArray);
- ns.appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);
- }
- private function playVideo():void
- {
- ns.resume();
- }
- private function pauseVideo():void
- {
- ns.pause();
- }
- private function stopVideo():void
- {
- ns.pause();
- ns.seek(0);
- }
- private var seekPoint:Number;
- private function videoSeek():void
- {
- seekPoint = 13472; // seek to a specific location
- ns.seek(seekPoint);
- }
- ]]>
- </fx:Script>
- <mx:VBox width="100%" height="100%">
- <mx:VBox height="85%" width="100%">
- <mx:UIComponent id="myUIComponent" width="100%" height="100%" />
- </mx:VBox>
- <mx:HBox>
- <s:Button label="Play" click="playVideo()"/>
- <s:Button label="Pause" click="pauseVideo()"/>
- <s:Button label="Stop" click="stopVideo()"/>
- <s:Button label="Seek" click="videoSeek()"/>
- </mx:HBox>
- </mx:VBox>
- </s:WindowedApplication>
Add Comment
Please, Sign In to add comment