加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex+Red5实现在线视频播放

发布时间:2020-12-15 04:46:13 所属栏目:百科 来源:网络整理
导读:?Flex3中对流媒体的支持不是很好,但是Flex4 却对rtmp协议有了很好的支持,能够自动识别rtmp协议,经本人认证确实如此,连接rtmp协议几乎不用多些什么代码,当然支持的视频当然是Flv格式啦。好了,请看本人的代码: ---点击阅读更多 ??? [html] view plain c
?Flex3中对流媒体的支持不是很好,但是Flex4 却对rtmp协议有了很好的支持,能够自动识别rtmp协议,经本人认证确实如此,连接rtmp协议几乎不用多些什么代码,当然支持的视频当然是Flv格式啦。好了,请看本人的代码:

--->点击阅读更多 ???

[html] view plain copy print ?
  1. <?xmlversionxmlversion="1.0"?encoding="utf-8"?>??
  2. <s:Application?xmlns:fx="http://ns.adobe.com/mxml/2009"??
  3. ??????????????xmlns:s="library://ns.adobe.com/flex/spark"??
  4. ??????????????xmlns:mx="library://ns.adobe.com/flex/mx"?minWidth="955"?minHeight="600"?>??
  5. ????<fx:Script>??
  6. ???????<![CDATA[?
  7. ???????????import?mx.collections.ArrayCollection;?
  8. ???????????import?mx.controls.Alert;?
  9. ???????????import?mx.controls.dataGridClasses.DataGridItemRenderer;?
  10. ???????????import?mx.events.FlexEvent;?
  11. ???????????private?var?conn:NetConnection;?
  12. ???????????private?var?stream:NetStream;?
  13. ???????????[Bindable]?
  14. ???????????private?var?fileUrl:String="";???//歌曲链接地址?
  15. ???????????[Bindable]?
  16. ???????????private?varsongList:ArrayCollection=new?ArrayCollection([?
  17. ??????????????{showName:'恋上另一个人',songer:'游鸿明',filmName:'chirsyu_lslygr.flv'},?
  18. ??????????????{showName:'一天一万年',filmName:'chirisyu_ytywn.flv'},?
  19. ??????????????{showName:'下沙',filmName:'chirisyu_xs.flv'},?
  20. ??????????????{showName:'五月的雪',filmName:'chirisyu_wydx.flv'},?
  21. ??????????????{showName:'楼下那个女人',filmName:'chirisyu_lxngnr.flv'},?
  22. ??????????????{showName:'白色恋人',filmName:'chirisyu_bslr.flv'}?
  23. ????????????]);?
  24. ???????????
  25. ???????????private?function?netStatusHandler(event:NetStatusEvent):void{?
  26. ??????????????switch(event.info.code)?
  27. ??????????????{?
  28. ??????????????????case?"NetConnection.Connect.Success":?
  29. ??????????????????{?
  30. ?????????????????????connectStream();?
  31. ?????????????????????break;?
  32. ??????????????????}?
  33. ??????????????????case?"NetStream.Play.StreamNotFound":{?
  34. ?????????????????????Alert.show("文件不存在!","提示");?
  35. ?????????????????????break;?
  36. ??????????????????}???
  37. ??????????????????
  38. ??????????????}?
  39. ???????????}?
  40. ???????????private?function?connectStream():void{?
  41. ??????????????stream=new?NetStream(conn);?
  42. ??????????????stream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);?
  43. ??????????????stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler);?
  44. ??????????????var?video:Video=new?Video();??//定义一个播放器?
  45. ??????????????video.width=300;?
  46. ??????????????video.height=335;?
  47. ??????????????video.attachNetStream(stream);?
  48. ??????????????stream.play(fileUrl);?
  49. ??????????????videoDisplay.addChild(video);?
  50. ???????????}?
  51. ???????????private?function?securityErrorHandler(event:SecurityErrorEvent):void{?
  52. ???????????}?
  53. ???????????private?function?asyncErrorHandler(event:AsyncErrorEvent):void{?
  54. ???????????}?
  55. ???????????
  56. ???????????protected?function?showList_clickHandler(event:MouseEvent):void?
  57. ???????????{?????????????
  58. ??????????????//?TODOAuto-generated?method?stub?
  59. ??????????????var?dataGridItemRenderer:DataGridItemRenderer=event.target?asDataGridItemRenderer;?
  60. ??????????????fileUrl=event.target.data['filmName'];?
  61. ??????????????if(dataGridItemRenderer!=null){?
  62. ??????????????????//需要捕获此异常,否则程序无法运行?
  63. ??????????????????try{?
  64. ?????????????????????if(conn.connected){?
  65. ?????????????????????????conn.close();?
  66. ?????????????????????}?
  67. ??????????????????}catch(e:Error){}?
  68. ??????????????????conn=new?NetConnection;?
  69. ??????????????????conn.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);?
  70. ??????????????????conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);?
  71. ??????????????????conn.connect("rtmp://localhost/oflaDemo");????//连接Red5服务器?
  72. ??????????????????
  73. ??????????????}?
  74. ???????????}?
  75. ???????????
  76. ???????]]>??
  77. ????</fx:Script>??
  78. ????<fx:Declarations>??
  79. ???????<!--?Place?non-visualelements?(e.g.,?services,?value?objects)?here?-->??
  80. ????</fx:Declarations>??
  81. ?????
  82. ????<mx:HDividedBox?x="194"?y="68"?width="750"?height="430"?fontSize="16"??fontWeight="bold">??
  83. ????????
  84. ???????<s:Panel?height="421"?width="50%"?title="MV列表"?>??
  85. ???????????<mx:DataGrid?width="100%"?height="100%"?dataProvider="{songList}"?id="showList"click="showList_clickHandler(event)">??
  86. ??????????????<mx:columns>??
  87. ??????????????????<mx:DataGridColumn?headerText="歌曲名"?dataField="showName"?width="250"/>??
  88. ??????????????????<mx:DataGridColumn?headerText="演唱者"?dataField="songer"?/>??
  89. ??????????????????<mx:DataGridColumn?headerText="链接地址"?dataField="filmName"?visible="false"?/>??
  90. ??????????????</mx:columns>??
  91. ???????????</mx:DataGrid>??
  92. ???????</s:Panel>??
  93. ???????<s:Panel?width="350"?height="419"?title="MV预览">??
  94. ???????????<s:VideoDisplay?id="videoDisplay"?x="20"?y="20"?width="100%"?height="100%"/>??
  95. ???????</s:Panel>??
  96. ????</mx:HDividedBox>??
  97. ?????
  98. </s:Application>??
  99. ???


?

? ? ? 部分注释详见代码中,点击左侧的MV名,即可在右侧播放,献上一幅图:

???



--->点击阅读更多 ???

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读