Thursday, January 7, 2010

Working with AS3 Video cuepoints

I have been working with cuePoints in flash video and so far have been unable to add actionscript cuePoints and then seek to them. (Update: see solution below)
  • Encode a video: "myVideo.flv" without embedded cuePoints
  • Attach the video to a FLV playback component "my_FLVPlybk"
  • Add cuepoints like this: my_FLVPlybk.addASCuePoint(15, "Cue1");
  • Set up an event Listener to see if the cuepoints are there:
my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener);

function cp_listener(eventObject:MetadataEvent):void {
trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
trace("Cue point name is: " + eventObject.info.name);
trace("Cue point type is: " + eventObject.info.type);
}

When you run the app, it all works expected. Once the cuepoints are reached it traces out each point. However when you try to go to the cuepoint using this method:

my_FLVPlybk.seekToNavCuePoint("Cue1");

It fails with this error:

VideoError: 1003: Invalid seek
at fl.video::FLVPlayback/seekToNavCuePoint()

Now, this last bit of code works fine if you embed navigation cuepoints in the video itself -- using Adobe Media Encoder (FLV only -- F4V seems not to support cuepoints--at least not well), but according to Adobe it should be possible to add the cuepoints and reference them through actionscript only. In this particular case its not a problem for me since its easier to add the cuepoints to the encoded video, but if anyone has come up with a solution, please post it!


***************************

Update: I found the solution on another forum (http://bit.ly/8EdgdN):

The answer is to locate the cuePoint using findCuePoint() -- which returns an associative array of the point -- and then get the value of "time". At this point you can just do a seek. The final code would be like this:

my_FLVPlybk.seek(my_FLVPlybk.findCuePoint("Cue4", CuePointType.ACTIONSCRIPT)["time"]);

No comments: