Flex中如何监测stateChange事件将VideoDisplay中视频当前ProgressBar中状态显示在List中的例子
By Minidxer | January 24, 2009
接下来的例子演示了Flex中如何监测stateChange事件,将VideoDisplay中视频当前ProgressBar中状态显示在List中。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="horizontal"
- verticalAlign="middle"
- backgroundColor="white" viewSourceURL="srcview/index.html">
- <mx:Script>
- <![CDATA[
- import mx.collections.ArrayCollection;
- import mx.events.VideoEvent;
- [Bindable]
- private var arrColl:ArrayCollection = new ArrayCollection();
- private const VIDEO_URL:String = "http://blog.minidx.com/ext/water.flv";
- private function videoDisplay_stateChange(evt:VideoEvent):void {
- /* videoDisplay.state == evt.state */
- arrColl.addItem({label:videoDisplay.state});
- progressBar.label = evt.state;
- }
- private function button_click(evt:MouseEvent):void {
- /* Reset ArrayCollection object. */
- arrColl = new ArrayCollection();
- /* Set the Canvas container to visible. */
- canvas.visible = true;
- /* If video is currently playing, stop playback. */
- if (videoDisplay.playing) {
- videoDisplay.stop();
- }
- /* Set VideoDisplay control's source property and start
- video playback. */
- videoDisplay.source = VIDEO_URL;
- videoDisplay.play();
- }
- private function videoDisplay_playheadUpdate(evt:VideoEvent):void {
- progressBar.setProgress(evt.playheadTime, videoDisplay.totalTime);
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:Button id="button"
- label="load movie"
- click="button_click(event);" />
- </mx:ApplicationControlBar>
- <mx:Canvas id="canvas" visible="false">
- <mx:VideoDisplay id="videoDisplay"
- playheadUpdateInterval="50"
- stateChange="videoDisplay_stateChange(event);"
- playheadUpdate="videoDisplay_playheadUpdate(event);" />
- <mx:ProgressBar id="progressBar"
- label=""
- labelPlacement="center"
- mode="manual"
- bottom="0"
- horizontalCenter="0" />
- </mx:Canvas>
- <mx:List id="list"
- dataProvider="{arrColl}"
- width="100" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
VideoDisplay |
No Comments » |
Tags: state, stateChange, VideoDisplay, VideoEvent