0

在开始播放电影之前,我添加了几个提示点,然后注册回调,并在每次命中时进行跟踪,如下所示:

    private function onCuePoint(evt:CuePointEvent):void {
        var cuePointObject:Object = {name:evt.cuePointName, time:evt.cuePointTime, type:evt.cuePointType};          

        trace("onCuePoint: " + evt.cuePointName + "=" + cueDict[evt.cuePointName] + " @t=" + cuePointObject.time + " playtime=" + playheadTime);
    }

您会认为cuePointObject.time大致等于电影的playheadTime。这是输出:

onCuePoint: cue3.4=cue3.4 @t=5.6 playtime=5.611
onCuePoint: cue1=cue1 @t=1 playtime=5.611
onCuePoint: cue2=cue2 @t=3 playtime=5.611
onCuePoint: cue2=cue2 @t=5 playtime=5.611
onCuePoint: cue3.1=cue3.1 @t=5 playtime=5.611
onCuePoint: cue3.1=cue3.1 @t=5.2 playtime=5.611
onCuePoint: cue3.2=cue3.2 @t=5.2 playtime=5.611
onCuePoint: cue3.2=cue3.2 @t=5.4 playtime=5.611
onCuePoint: cue3.3=cue3.3 @t=5.4 playtime=5.611
onCuePoint: cue3.3=cue3.3 @t=5.6000000000000005 playtime=5.611
onCuePoint: cue3.4=cue3.4 @t=5.8 playtime=5.888
onCuePoint: cue3.5=cue3.5 @t=5.8 playtime=5.888
onCuePoint: cue4=cue4 @t=10 playtime=9.92
onCuePoint: cue1=cue1 @t=11 playtime=11.221

看起来好像它等到“cue3.4”被触发,然后由于某种原因其余的跟随。它们作为数组添加到视频中,大致按照它们应该出现的顺序排序,因此 cue3.4 不是第一个。

4

1 回答 1

0

我调试了一段时间后发现了问题,所以我在这里发布解决方案,以防其他人偶然发现它。

这是 Flex 中的一个错误,我使用的是 v3.6,但我不知道它是否已修复。当 cue 添加到 CuePointManager 时,它会根据 cue 的时间进行插入排序。然而,在算法的某一时刻,它会像这样对数字进行四舍五入:

var compTime1:Number = Math.round(time * 1000);
var compTime2:Number = Math.round(cuePoint.time * 1000);

然后,它检查比较方法返回的索引(它说应该插入提示)而不使用舍入:

index = getCuePointIndex(cuePoints, true, copy.time, null, 0, 0);
index = (cuePoints[index].time > copy.time) ? 0 : index + 1;

由于浮点错误,我在 5.6000000000000005 触发的 3.3 提示具有该值 - 我已将 0.2 添加到 5.4。因此,当getCuePointIndex返回正确的index时,它会在第二行设置为0,将其放在列表的首位。

我的解决方法是在添加提示之前自己简单地对提示时间进行四舍五入:

trace("pushing cue " + c.id + "@"+ c.time + " - "  + ((c.time + c.duration) * 1000) / 1000);
cuePointArr.push({name:c.id + "_start", time:Math.round(c.time * 1000) / 1000,              type:"actionscript"});
cuePointArr.push({name:c.id + "_stop",  time:Math.round((c.time + c.duration) * 1000) / 1000, type:"actionscript"});

(注意:我已经添加了“_start”和“_stop”部分,因为我遇到了两个同名提示的问题)

希望这对某人有帮助!

于 2011-02-03T09:50:59.567 回答