/* Copyright (C) 2009 Sven Buschbeck, svenbuschbeck.net This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package net.svenbuschbeck.flex.video { import mx.controls.videoClasses.CuePointManager; import mx.controls.videoClasses.VideoPlayer; import mx.events.MetadataEvent; import mx.events.VideoEvent; import mx.utils.ObjectUtil; import mx.core.mx_internal; use namespace mx_internal; public class AdvCuePointManager extends CuePointManager { private var video:VideoPlayer; public function AdvCuePointManager(owner:VideoPlayer, id:uint=0) { super(owner, id); video = owner; video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, onPlayheadUpdate); } public function onPlayheadUpdate(event:VideoEvent):void { var cuePoints:Array = getCuePoints(); // @TODO: cuePoints must be ordered ascending if (cuePoints == null || cuePoints.length < 1) { return; } var seconds:int = video.playheadTime; var newCurrentCuePoint:Object = cuePoints[0]; for (var x:uint = 0; x < cuePoints.length-1; x++ ) { var nextCuePoint:Object = cuePoints[x+1]; if (nextCuePoint.time > seconds) { // if the next cue point is already behind the current time, we found our current cue point break; } newCurrentCuePoint = nextCuePoint; } currentCuePoint = newCurrentCuePoint; } override mx_internal function dispatchCuePoints():void { // disabling inherited method, which does not trigger cue points properly } private var _currentCuePoint:Object; public function get currentCuePoint():Object { return _currentCuePoint } public function set currentCuePoint(cuePoint:Object):void { if (currentCuePoint == null || (cuePoint.time != currentCuePoint.time /*&& cuePoint.time != currentCuePoint.time*/)) { if (currentCuePoint != null) { trace("current.time/name: "+currentCuePoint.time+"/"+currentCuePoint.name+"; new: "+cuePoint.time+"/"+cuePoint.name); } _currentCuePoint = cuePoint; var metadataEvent:MetadataEvent = new MetadataEvent(MetadataEvent.CUE_POINT); metadataEvent.info = ObjectUtil.copy(currentCuePoint); video.dispatchEvent(metadataEvent); } return; } } }