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. <?xmlversion="1.0"encoding="utf-8"?>
  2. <videos>
  3. <videoname="France"id="france"xlink="assets/videos/france.flv"/>
  4. <videoname="Japan"id="japan"xlink="assets/videos/japan.flv"/>
  5. </videos>

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

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <mx:VBoxxmlns:mx="http://www.adobe.com/2006/mxml"
  3. width="100%"height="100%">
  4. <mx:Script>
  5. <![CDATA[
  6. [Bindable]privatevar_vidData:String;
  7. publicfunctionsetvidData(video:String):void{
  8. _vidData=video;
  9. }
  10. ]]>
  11. </mx:Script>
  12. <mx:VideoDisplayid="vid"
  13. autoPlay="false"source="{_vidData}"/>
  14. <mx:HBox>
  15. <mx:Buttonlabel="Play"click="vid.play();"/>
  16. <mx:Buttonlabel="Pause"click="vid.pause();"/>
  17. <mx:Buttonlabel="Stop"click="vid.stop();"/>
  18. </mx:HBox>
  19. </mx:VBox>

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

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
  3. creationComplete="init()"xmlns:comp="components.*">
  4. <mx:Script>
  5. <![CDATA[
  6. importmx.collections.XMLListCollection;
  7. importmx.rpc.events.ResultEvent;
  8. [Bindable]publicvarvideosDP:XMLListCollection=newXMLListCollection();
  9. privatefunctioninit():void{
  10. videosRequest.send();
  11. }
  12. privatefunctionvideosResultHandler(event:ResultEvent):void{
  13. varlist:XMLList=newXMLList(event.result..video);
  14. videosDP=newXMLListCollection(list);
  15. }
  16. ]]>
  17. </mx:Script>
  18. <mx:HTTPServiceid="videosRequest"useProxy="false"resultFormat="e4x"
  19. result="videosResultHandler(event)"url="data/videoData.xml"/>
  20. <mx:Repeaterid="myRepeater"dataProvider="{videosDP}">
  21. <mx:Labeltext="{'Path:'+myRepeater.currentItem.@xlink}"/>
  22. <comp:VideoCompvidData="{myRepeater.currentItem.@xlink}"/>
  23. </mx:Repeater>
  24. </mx:Application>

Related files for download

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值