Monday, January 31, 2011

AS 2.0 : Streaming Videos

I'm freeze-drying the following after an arduous search. Documentation for this Actionscript 2.0 Streaming Video recipe is becoming as scarce as unicorns. Note, this chunk of Nyum-nyum code is timeline based and does not include action-scripted player controllers like pause or volume (sorry!).


1. But First-Things first: Create a video object on the stage :

File>Import>Import Video


2. A dialog box will prompt for the remote location of the video. The video object will be created on the stage as a rectangular outline.


3. Place the the following in the very first frame.




//......................Cross Domain

Security.allowDomain('*');


//.........................Define Establish A STREAM

var nc:NetConnection = new NetConnection();

nc.connect(null);

var ns:NetStream = new NetStream(nc);

//.........................SHOW VIDEO

myVideo.attachVideo(ns);

myVideo.smoothing = true;

//

ns.setBufferTime(1);

//........................................

ns.onMetaData = function(item:Object):Void {

trace("metaData");

};

ns.onCuePoint = function(item:Object):Void {

trace("cuePoint");

trace(item.name+"\t"+item.time);

};


//.......................STATUS of STREAM

ns.onStatus = function(info) {

//

if (info.code == "NetStream.Buffer.Full") {

trace("I'm Ready To Stream");

}

//

if (info.code == "NetStream.Play.Start") {

trace("start Streaming");

}

// ....... IF FINISH do this

if (info.code == "NetStream.Play.Stop") {

ns.close();

//you can specify some action here

trace("end Streaming");

}

};


//............... Play This VIDEO FROM This Server Location

//...............You can assign this to a Button Action

ns.play("http://myvideolocation.com/myvideo.swf");

No comments:

Post a Comment