Wednesday, June 23, 2010

AS3.0 adding total time and lapsed time to a FLVPlayback Video Player

player.addEventListener(MetadataEvent.METADATA_RECEIVED, timeListener);

function timeListener(eventObject:MetadataEvent):void {
var totalSeconds = String(eventObject.info.duration);
var durationTime:String = (totalSeconds > 3600 ? Math.round(totalSeconds / 3600) + ":" : "") + (totalSeconds % 3600 < 600 ? "0" : "") + Math.round(totalSeconds % 3600/60) + ":" + (totalSeconds % 60 < 10 ? "0":"") + Math.round(totalSeconds % 60);
TxttotalTime.text = durationTime;
}

stage.addEventListener(Event.ENTER_FRAME, updateTime);

function updateTime (ev:Event):void {
var elapsedSeconds = String(player.playheadTime);
var runTime:String = (elapsedSeconds > 3600 ? Math.floor(elapsedSeconds / 3600) + ":" : "") + (elapsedSeconds % 3600 < 600 ? "0" : "") + Math.floor(elapsedSeconds % 3600/60) + ":" + (elapsedSeconds % 60 < 10 ? "0":"") + Math.floor(elapsedSeconds % 60) ;
elapsedTime.text = runTime;
}

Regards, Dipak