Flex 连接远程服务器(转载)

转载http://hi.baidu.com/udking_love/blog/item/3bd737d1b9a525d4572c84cc.html
在Flex中利用NetConnection, NetStream和Video类显示video文件
2009年02月09日 星期一 下午 10:25

下 面的例子说明了利用NetConnection, NetStream和Video类,如何在Flex应用中显示一个FLV文件,以及如何使用onMetaData和onCuePoint事件处理视频数据 (video meta data)和提示点(cue points)。

  1. <? xml version = " 1.0 " encoding = " utf-8 " ?>
  2. <!-- http : //blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/ -->
  3. < mx : Application xmlns : mx = " http://www.adobe.com/2006/mxml "
  4. layout = " vertical "
  5. verticalAlign = " middle "
  6. backgroundColor = " white "
  7. creationComplete = " init(); " viewSourceURL = " srcview/index.html " >
  8. < mx : Script >
  9. <! [ CDATA [
  10. import mx . utils . ObjectUtil ;
  11. private var nc : NetConnection ;
  12. private var ns : NetStream ;
  13. private var video : Video ;
  14. private var meta : Object ;
  15. private function init () : void {
  16. var nsClient : Object = {} ;
  17. nsClient . onMetaData = ns_onMetaData ;
  18. nsClient . onCuePoint = ns_onCuePoint ;
  19. nc = new NetConnection () ;
  20. nc . connect ( null ) ;
  21. ns = new NetStream ( nc ) ;
  22. ns . play ( " http://www.helpexamples.com/flash/video/cuepoints.flv " ) ;
  23. ns . client = nsClient ;
  24. video = new Video () ;
  25. video . attachNetStream ( ns ) ;
  26. uic . addChild ( video ) ;
  27. }
  28. private function ns_onMetaData ( item : Object ) : void {
  29. trace ( " meta " ) ;
  30. meta = item ;
  31. // Resize Video object to same size as meta data.
  32. video . width = item . width ;
  33. video . height = item . height ;
  34. // Resize UIComponent to same size as Video object.
  35. uic . width = video . width ;
  36. uic . height = video . height ;
  37. panel . title = " framerate: " + item . framerate ;
  38. panel . visible = true ;
  39. trace ( ObjectUtil . toString ( item )) ;
  40. }
  41. private function ns_onCuePoint ( item : Object ) : void {
  42. trace ( " cue " ) ;
  43. }
  44. ]] >
  45. < / mx:Script>
  46. <mx:Panel id="panel" visible="false">
  47. <mx:UIComponent id="uic" / >
  48. < mx : ControlBar >
  49. < mx : Button label = " Play/Pause " click = " ns.togglePause(); " / >
  50. <mx:Button label="Rewind" click="ns.seek(0); ns.pause();" / >
  51. < / mx:ControlBar>
  52. < / mx : Panel >
  53. < / mx:Application>

具体效果参见原文地址:

http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值