Skip to content

Instantly share code, notes, and snippets.

@mattlundstrom
Created June 15, 2012 18:52
Show Gist options
  • Save mattlundstrom/2938153 to your computer and use it in GitHub Desktop.
Save mattlundstrom/2938153 to your computer and use it in GitHub Desktop.
Flash Video
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = nsOnMetaData;
ns.client.onCuePoint = nsOnCuePoint;
ns.addEventListener(NetStatusEvent.NET_STATUS, nsOnNetStatus);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
var video:Video = new Video();
addChild(video)
video.attachNetStream(ns);
ns.play("video.flv");
// VIDEO EVENTS
function nsOnMetaData(item:Object):void {
trace("METADATA:");
}
function nsOnCuePoint(item:Object):void {
trace("CUEPOINT:");
trace(item.name + "\t" + item.time);
switch (item.name) {
case "cuepointName" :
// WHEN CP1 HITS DO THIS
break;
}
}
function nsOnNetStatus(e:NetStatusEvent):void {
trace("NETSTATUS:");
trace(e.info.code);
switch (e.info.code) {
case "NetStream.Play.Start" :
break;
case "NetStream.Play.Stop" :
// WHEN THE VIDEO ENDS CODE HERE IS EXECUTED
break;
case "NetStream.Buffer.Empty" :
break;
}
}
function onAsyncError(e:AsyncErrorEvent):void {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment