Monday, February 16, 2009

How to convert XMP Cuepoint Time to Millisecond in AS3

Following my article

http://younsi.blogspot.com/2008/10/flv-cuepoints-in-flash-cs3-with-flash.html

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("http://ns.adobe.com/xmp/1.0/DynamicMedia/");
var rdf:Namespace = new Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");

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
article

http://younsi.blogspot.com/2008/12/interactive-video-in-flash-using-f4v.html

No comments: