var vid:Video=new Video(320,240);
videoPlayerHost.addChild(vid);
var nc:NetConnection=new NetConnection ;
nc.connect(null);
var ns:NetStream=new NetStream(nc);
vid.attachNetStream(ns);
var infoContainer:Object;
var listener:Object=new Object ;
listener.onMetaData=function(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
tmrDisplay.start();
infoContainer=info;
};
ns.client=listener;
ns.play("myVideo.flv");
var tmrDisplay:Timer=new Timer(10);
tmrDisplay.addEventListener(TimerEvent.TIMER,updateDisplay);
var playbackPercentComplete:Number=0;
function updateDisplay(e:TimerEvent):void {
playbackPercentComplete=ns.time/infoContainer.duration;
trace("PLAYING... elapsed time="+ns.time+", video length="+infoContainer.duration+", percent complete="+playbackPercentComplete);
if (ns.time>infoContainer.duration) {
playbackPercentComplete=0;
tmrDisplay.stop();
trace("done playing")
}
}
//ns.pause() will pause the video
//ns.resume() will resume the video
//ns.seek(0) will jump the playhead to the beginning
Thursday, November 6, 2008
Simple AS3 Video FLV Player
Here are the basics for loading an external FLV and reading progress.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment