Monday, February 16, 2009

How to convert XMP Cuepoint Time to Millisecond in AS3

Following my article

I wanted to explain to the Flash Community how they can interpret XMP Cuepoint
in millisecond time that Flash Can understand

To synchronize an action for a cue point in an F4V video file, you must retrieve the cue point data from either the onMetaData() or the onXMPData() callback functions and trigger the cue point using the Timer class in ActionScript 3.0. For more information on F4V cue points, see Using onXMPData().

Each XMP Tracks do have a framerate value
first get the nTracksFrameRate and then for each cuepoint time
devide the value read from XMP by the TrackFrameRate and you will
now have a time in millisecond.

function getFLVCuepointsFromXMP(onXMPString:String):void {
var onXMPXML = new XML(onXMPString);
var onXMPTracksXML;
var onXMPCuepointsXML;
var cuePointCount:Number = 0;
var strFrameRate:String;
var nTracksFrameRate:Number;
var cuePoints:Array = new Array();
var cuePoint:Object;

// Set up namespaces to make referencing easier
var xmpDM:Namespace = new Namespace("");
var rdf:Namespace = new Namespace("");

var strTracks:String = "";

if (verbose) {
trace("###### TRACKS");

// This iteration get all the Tracks
for each (var it:XML in onXMPXML..xmpDM::Tracks)
var strTrackName:String = it.rdf::Bag.rdf::li.rdf::Description.@xmpDM::trackName;
var strFrameRateXML:String = it.rdf::Bag.rdf::li.rdf::Description.@xmpDM::frameRate;
strFrameRate = strFrameRateXML.substr(1,strFrameRateXML.length);

nTracksFrameRate = Number(strFrameRate);

cuePoint["time"] = nStartTime/nTracksFrameRate;


Hope this will solve few headhaches...

Now implement a timer and sync your Cue Point the way you want using Action Script 3 code.

I am talking about the best use cases of XMP Cue points in an older

No comments: