使用提示点提示点是一个点,在播放视频文件时,视频播放器在该点处调度一个 cuePoint 事件。您可以在想为网页上的其它元素执行动作时向 FLV 文件添加提示点。例如,您可能想要显示文本或图形,或者要与 Flash 动画同步,或者要影响 FLV 文件的播放,具体为暂停 FLV 文件、在视频中搜索不同点或切换到不同 FLV 文件。提示点允许您接收 ActionScript 代码中的控制以将 FLV 文件中的点与网页上的其它动作同步。 有三种类型的提示点:导航、事件和 ActionScript。导航提示点和事件提示点也称作嵌入式 提示点,因为它们嵌入在 FLV 文件流和 FLV 文件的元数据包中。 导航提示点允许您搜索 FLV 文件中的特定帧,因为它在尽可能接近您指定的时间在 FLV 文件内创建关键帧。关键帧是在 FLV 文件流的图像帧之间出现的数据段。在您搜索导航提示点时,组件将搜索到该关键帧并启动 cuePoint 事件。 事件提示点 使您能够将 FLV 文件内的时间点与网页上的外部事件同步。cuePoint 事件在指定的时间精确发生。您可以使用视频导入向导或 Flash Video Encoder,在 FLV 文件中嵌入导航提示点和事件提示点。有关视频导入向导和 Flash 视频编码器的详细信息,请参阅《使用 Flash》中的第 16 章,“使用视频”。 ActionScript 提示点 是一种外部提示点,您可以通过组件的“Flash 视频提示点”对话框或通过 FLVPlayback.addASCuePoint() 方法添加。该组件在 FLV 文件之外存储和跟踪 ActionScript 提示点,因此,这些提示点在精确性上要低于嵌入式提示点。ActionScript 提示点精确度为十分之一秒。您可以通过降低 playheadUpdateInterval 属性值来提高 ActionScript 提示点的精确度,因为组件在播放头更新时会为 ActionScript 提示点生成 cuePoint 事件。有关详细信息,请参阅《用于 Adobe® Flash® Professional CS5 的 ActionScript® 3.0 参考》中的 FLVPlayback.playheadUpdateInterval 属性。 在 ActionScript 和 FLV 文件的元数据内,提示点表示为具有以下属性的对象:name、time、type 和 parameters。name 属性是一个字符串,其中包含为提示点分配的名称。time 属性是一个数字,表示提示点的发生时间,用小时、分钟、秒和毫秒 (HH:MM:SS.mmm) 表示。type 属性是一个字符串,根据您创建的提示点的类型,此字符串的值可以是 "navigation"、"event" 或 "actionscript"。parameters 属性是包含指定的名称-值对的数组。 在发生 cuePoint 事件时,可以通过 info 属性在事件对象中提供提示点对象。 使用“Flash 视频提示点”对话框通过在“组件”检查器中双击 cuePoints 参数的 Value 单元格,可以打开“Flash 视频提示点”对话框。对话框类似于下图: 该对话框显示嵌入式提示点和 ActionScript 提示点。可以使用此对话框添加和删除 ActionScript 提示点以及提示点参数。还可以启用或禁用嵌入式提示点。但是,不能添加、更改或删除嵌入式提示点。 添加 ActionScript 提示点:
在 ActionScript 中使用提示点您可以使用 ActionScript 添加 ActionScript 提示点、侦听 cuePoint 事件、查找任何类型或特定类型的提示点、搜索导航提示点、启用或禁用提示点、检查是否启用了某个提示点以及删除提示点。 本节中的示例使用名为 cuepoints.flv 的 FLV 文件,它包含以下 3 个提示点:
添加 ActionScript 提示点您可以使用 addASCuePoint() 方法将 ActionScript 提示点添加到 FLV 文件。以下示例在 FLV 文件可供播放时向该 FLV 文件添加 2 个 ActionScript 提示点。该示例使用提示点对象添加第 1 个提示点,在其属性中指定该提示点的时间、名称和类型。第 2 个调用使用该方法的 time 和 name 参数指定时间和名称。 // Requires an FLVPlayback instance called my_FLVPlybk on Stage import fl.video.*; import fl.video.MetadataEvent; my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/cuepoints.flv" var cuePt:Object = new Object(); //create cue point object cuePt.time = 2.02; cuePt.name = "ASpt1"; cuePt.type = "actionscript"; my_FLVPlybk.addASCuePoint(cuePt);//add AS cue point // add 2nd AS cue point using time and name parameters my_FLVPlybk.addASCuePoint(5, "ASpt2"); 有关详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.addASCuePoint() 方法。 侦听 cuePoint 事件cuePoint 事件允许您在发生 cuePoint 事件时接收 ActionScript 代码中的控制。在以下示例中,当提示点出现时,cuePoint 侦听器会调用一个事件处理函数,该事件处理函数显示 playheadTime 属性的值以及提示点的名称和类型。请将此例与上节中的示例“添加 ActionScript 提示点”结合起来,以查看结果。 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); } 有关 cuePoint 事件的详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.cuePoint 事件。 查找提示点通过使用 ActionScript,您可以找到任何类型的提示点、找到与某个时间最接近的提示点或者使用具体名称找到下一个提示点。 在以下示例中,ready_listener() 事件处理函数调用 findCuePoint() 方法查找提示点 ASpt1,然后调用 findNearestCuePoint() 方法查找最接近提示点 ASpt1 的时间的导航提示点: import fl.video.FLVPlayback; import fl.video.CuePointType; import fl.video.VideoEvent; my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/cuepoints.flv" var rtn_obj:Object; //create cue point object my_FLVPlybk.addASCuePoint(2.02, "ASpt1");//add AS cue point function ready_listener(eventObject:VideoEvent):void { rtn_obj = my_FLVPlybk.findCuePoint("ASpt1", CuePointType.ACTIONSCRIPT); traceit(rtn_obj); rtn_obj = my_FLVPlybk.findNearestCuePoint(rtn_obj.time, CuePointType.NAVIGATION); traceit(rtn_obj); } my_FLVPlybk.addEventListener(VideoEvent.READY, ready_listener); function traceit(cuePoint:Object):void { trace("Cue point name is: " + cuePoint.name); trace("Cue point time is: " + cuePoint.time); trace("Cue point type is: " + cuePoint.type); } 在以下示例中,ready_listener() 事件处理函数查找提示点 ASpt,并且调用 findNextCuePointWithName() 方法查找同名的下一个提示点: import fl.video.*; my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/cuepoints.flv" var rtn_obj:Object; //create cue point object my_FLVPlybk.addASCuePoint(2.02, "ASpt");//add AS cue point my_FLVPlybk.addASCuePoint(3.4, "ASpt");//add 2nd Aspt my_FLVPlybk.addEventListener(VideoEvent.READY, ready_listener); function ready_listener(eventObject:VideoEvent):void { rtn_obj = my_FLVPlybk.findCuePoint("ASpt", CuePointType.ACTIONSCRIPT); traceit(rtn_obj); rtn_obj = my_FLVPlybk.findNextCuePointWithName(rtn_obj); traceit(rtn_obj); } function traceit(cuePoint:Object):void { trace("Cue point name is: " + cuePoint.name); trace("Cue point time is: " + cuePoint.time); trace("Cue point type is: " + cuePoint.type); } 有关查找提示点的详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.findCuePoint()、FLVPlayback.findNearestCuePoint() 和 FLVPlayback.findNextCuePointWithName() 方法。 搜索导航提示点您可以搜索导航提示点、搜索指定时间的下一个导航提示点以及搜索指定时间的前一个导航提示点。下面的示例播放 FLV 文件 cuepoints.flv,并在发生 ready 事件时搜索位于 7.748 的提示点。在发生 cuePoint 事件时,该示例调用 seekToPrevNavCuePoint() 方法以搜索第一个提示点。在 cuePoint 事件发生时,该示例调用 seekToNextNavCuePoint() 方法,通过将 eventObject.info.time(这是当前提示点的时间)加上 10 秒来搜索最后一个提示点。 import fl.video.*; my_FLVPlybk.addEventListener(VideoEvent.READY, ready_listener); function ready_listener(eventObject:Object):void { my_FLVPlybk.seekToNavCuePoint("point2"); } my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener); function cp_listener(eventObject:MetadataEvent):void { trace(eventObject.info.time); if(eventObject.info.time == 7.748) my_FLVPlybk.seekToPrevNavCuePoint(eventObject.info.time - .005); else my_FLVPlybk.seekToNextNavCuePoint(eventObject.info.time + 10); } my_FLVPlybk.source = "http://helpexamples.com/flash/video/cuepoints.flv"; 有关详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.seekToNavCuePoint()、FLVPlayback.seekToNextNavCuePoint() 和 FLVPlayback.seekToPrevNavCuePoint() 方法。 启用和禁用嵌入式 FLV 文件提示点您可以通过 setFLVCuePointEnabled() 方法启用和禁用嵌入式 FLV 文件提示点。禁用的提示点不触发 cuePoint 事件,并且不与 seekToCuePoint()、seekToNextNavCuePoint() 或 seekToPrevNavCuePoint() 方法一起使用。不过,您可以使用 findCuePoint()、findNearestCuePoint() 和 findNextCuePointWithName() 方法找到禁用的提示点。 您可以使用 isFLVCuePointEnabled() 方法来测试是否启用了嵌入式 FLV 文件提示点。以下示例在视频准备播放时禁用嵌入式提示点 point2 和 point3。但在发生第一个 cuePoint 事件时,事件处理函数将进行测试以确定提示点 point3 是否被禁用,如果确定该提示点被禁用,则启用它。 import fl.video.*; my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/cuepoints.flv"; my_FLVPlybk.addEventListener(VideoEvent.READY, ready_listener); function ready_listener(eventObject:VideoEvent):void { my_FLVPlybk.setFLVCuePointEnabled(false, "point2"); my_FLVPlybk.setFLVCuePointEnabled(false, "point3"); } my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener); function cp_listener(eventObject:MetadataEvent):void { trace("Cue point time is: " + eventObject.info.time); trace("Cue point name is: " + eventObject.info.name); trace("Cue point type is: " + eventObject.info.type); if (my_FLVPlybk.isFLVCuePointEnabled("point2") == false) { my_FLVPlybk.setFLVCuePointEnabled(true, "point2"); } } 有关详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.isFLVCuePointEnabled() 和 FLVPlayback.setFLVCuePointEnabled() 方法。 删除 ActionScript 提示点您可以使用 removeASCuePoint() 方法删除 ActionScript 提示点。以下示例在提示点 ASpt1 发生时删除提示点 ASpt2: import fl.video.*; my_FLVPlybk.source = "http://www.helpexamples.com/flash/video/cuepoints.flv" my_FLVPlybk.addASCuePoint(2.02, "ASpt1");//add AS cue point my_FLVPlybk.addASCuePoint(3.4, "ASpt2");//add 2nd Aspt my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener); function cp_listener(eventObject:MetadataEvent):void { trace("Cue point name is: " + eventObject.info.name); if (eventObject.info.name == "ASpt1") { my_FLVPlybk.removeASCuePoint("ASpt2"); trace("Removed cue point ASpt2"); } } 有关详细信息,请参阅 Adobe ActionScript 3.0 Reference for the Adobe Flash Platform 中的 FLVPlayback.removeASCuePoint()。 |
![]() |