Multiple VideoDisplay and playback controls for each using repeater

 

Problem Summary

I want to dynamically generate a VideoDisplay control and playback controls for each using repeater and data in an XML file.

Solution Summary

Use a component housing the VideoDisplay control and an HBox with Play, Stop, and Pause buttons, and use the component in a Repeater, that takes data from an XML file.

Explanation

See the zip file for the exported project.

----- assets/videos/france.flv -----


----- assets/videos/japan.flv -----
 

----- data/videoData.xml -----

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <videos>
  3.   <video name="France" id="france" xlink="assets/videos/france.flv" />
  4.   <video name="Japan" id="japan" xlink="assets/videos/japan.flv" />
  5. </videos>

----- components/VideoComp.mxml -----

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
  3.   width="100%" height="100%">
  4.   <mx:Script>
  5.     <![CDATA[
  6.       [Bindable] private var _vidData:String;
  7.       
  8.       public function set vidData(video:String):void{
  9.         _vidData = video;
  10.       }
  11.     ]]>
  12.   </mx:Script>
  13.   <mx:VideoDisplay id="vid" 
  14.     autoPlay="false" source="{_vidData}"/>
  15.   <mx:HBox>
  16.     <mx:Button label="Play" click="vid.play();"/>
  17.     <mx:Button label="Pause" click="vid.pause();"/>
  18.     <mx:Button label="Stop" click="vid.stop();"/>
  19.   </mx:HBox> 
  20. </mx:VBox>

----- MultipleVideos.mxml -----

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.   creationComplete="init()" xmlns:comp="components.*">
  4.   <mx:Script>
  5.     <![CDATA[      
  6.       import mx.collections.XMLListCollection;
  7.       import mx.rpc.events.ResultEvent;
  8.       [Bindable] public var videosDP:XMLListCollection = new XMLListCollection();
  9.             
  10.       private function init():void{
  11.         videosRequest.send();
  12.       }
  13.       
  14.       private function videosResultHandler(event:ResultEvent):void{
  15.         var list:XMLList = new XMLList(event.result..video);
  16.         videosDP = new XMLListCollection(list);
  17.       }
  18.     ]]>
  19.   </mx:Script>      
  20.   <mx:HTTPService id="videosRequest" useProxy="false" resultFormat="e4x"
  21.     result="videosResultHandler(event)" url="data/videoData.xml"/>
  22.   <mx:Repeater id="myRepeater" dataProvider="{videosDP}">
  23.     <mx:Label text="{'Path:' + myRepeater.currentItem.@xlink}"/>
  24.     <comp:VideoComp vidData="{myRepeater.currentItem.@xlink}"/>
  25.   </mx:Repeater>
  26. </mx:Application>

 

Related files for download

You need to have two flv files, france.flv and japan.flv.
MultipleVideos.zip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值