Jun 30
在前面的Flex中如何利用cuePointManager属性和addCuePoint事件往FLV中添加ActionScript暗点的例子中,我们了解了Flex中如何利用cuePointManager属性和addCuePoint事件,往FLV中添加ActionScript暗点。接下来的例子则演示了Flex中如何利用VideoDisplay和HSlider控件,给FLV添加一个“清道夫”。
由于Demo循环播放,考虑到一部分同学可能不喜欢所以放在单独的页面中:
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white" viewSourceURL="srcview/index.html">
- <mx:Script>
- <![CDATA[
- private function formatTime(item:Date):String {
- return dateFormatter.format(item);
- }
- private function videoDisplay_playheadUpdate():void {
- /* If playhead time is 0, set to 100ms so the DateFormatter doesnt return an empty string. */
- var pT:Number = videoDisplay.playheadTime || 0.1;
- var tT:Number = videoDisplay.totalTime;
- /* Convert playheadTime and totalTime from seconds to milliseconds and create new Date objects. */
- var pTimeMS:Date = new Date(pT * 1000);
- var tTimeMS:Date = new Date(tT * 1000);
- timeLabel.text = formatTime(pTimeMS) + " / " + formatTime(tTimeMS);
- }
- private function slider_thumbPress():void {
- videoDisplay.pause();
- }
- private function slider_thumbRelease():void {
- videoDisplay.playheadTime = slider.value;
- videoDisplay.play();
- }
- private function videoDisplay_ready():void {
- videoDisplay.visible = true;
- controlBar.visible = true;
- }
- ]]>
- </mx:Script>
- <!-- Only show minutes and seconds. -->
- <mx:DateFormatter id="dateFormatter" formatString="NN:SS" />
- <mx:Zoom id="zoom" />
- <mx:Panel title="{videoDisplay.source.split('/').pop()} ({videoDisplay.state})">
- <mx:VideoDisplay id="videoDisplay" visible="false" showEffect="{zoom}"
- playheadUpdate="videoDisplay_playheadUpdate()"
- ready="videoDisplay_ready()"
- rewind="videoDisplay.play()"
- source="http://blog.minidx.com/ext/cuepoints.flv" />
- <mx:ControlBar id="controlBar" visible="false">
- <mx:HSlider id="slider" width="100%"
- allowTrackClick="false"
- invertThumbDirection="true"
- liveDragging="false"
- maximum="{videoDisplay.totalTime}"
- minimum="0"
- thumbPress="slider_thumbPress()"
- thumbRelease="slider_thumbRelease()"
- tickInterval="1"
- value="{videoDisplay.playheadTime}" />
- <mx:Label id="timeLabel" textAlign="right" />
- </mx:ControlBar>
- </mx:Panel>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
