Java and flex Study Notes (17)-Flex + red5 online video playback

Source: Internet
Author: User

Every time I look at my Flex position on the recruitment website, I always see some companies that require a certain understanding of red5. After I have some knowledge of the red5 server, I can't wait to implement this Flex + red5 video playing function. After several nights of exploration, I finally got it tonight. That exciting thing ~


Flex3 does not provide good support for streaming media, but flex4 does provide great support for the rtmp protocol. It can automatically identify the rtmp protocol. I have personally certified this, there is almost no need for more code to connect to the rtmp protocol. Of course, the supported videos are of course FLV format. Well, please refer to your code:


<? Xmlversion = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "minwidth =" 955 "minheight =" 600 "> <FX: SCRIPT> <! [CDATA [import MX. collections. arraycollection; import MX. controls. alert; import MX. controls. datagridclasses. datagriditemrenderer; import MX. events. flexevent; private var Conn: netconnection; private var stream: netstream; [Bindable] private var fileurl: String = ""; // song link address [Bindable] private varsonglist: arraycollection = new arraycollection ([{showname: 'fall in love with another person ', songer: 'youhongming', filmname: 'chirsyu _ lslygr. flv' }, {Showname: '1st year', songer: 'youhongming ', filmname: 'chirisyu _ ytywn. flv'}, {showname: 'shasha ', songer: 'youhongming', filmname: 'chirisyu _ Xs. flv'}, {showname: 'snow of June 11', songer: 'youhongming ', filmname: 'chirisyu _ wydx. flv'}, {showname: 'Woman downstairs ', songer: 'youhongming', filmname: 'chirisyu _ lxngnr. flv'}, {showname: 'White loan', songer: 'youhongming ', filmname: 'chirisyu _ bslr. flv'}]); Private function netstatushandler (Event: netstatusevent): void {Switch (event.info. code ){ Case "netconnection. Connect. Success": {connectstream (); break;} case "netstream. Play. streamnotfound": {alert. Show ("the file does not exist! "," Prompt "); break ;}} private function connectstream (): void {stream = new netstream (conn); stream. addeventlistener (netstatusevent. net_status, netstatushandler); stream. addeventlistener (asyncerrorevent. async_error, asyncerrorhandler); var video: Video = new video (); // defines a player video. width = 300; video. height = 335; video. attachnetstream (Stream); stream. play (fileurl); videodisplay. addchild (video);} private func Tion securityerrorhandler (Event: securityerrorevent): void {} private function asyncerrorhandler (Event: asyncerrorevent): void {} protected function showlist_clickhandler (Event: mouseevent ): void {// todoauto-generated method stub var datagriditemrenderer: datagriditemrenderer=event.tar get asdatagriditemrenderer; fileurl#event.tar get. data ['filmname']; If (datagriditemrenderer! = NULL) {// This exception needs to be caught; otherwise, the program cannot run try {If (Conn. connected) {Conn. close () ;}} catch (E: Error) {} conn = new netconnection; Conn. addeventlistener (netstatusevent. net_status, netstatushandler); Conn. addeventlistener (securityerrorevent. security_error, securityerrorhandler); Conn. connect ("rtmp: // localhost/oflademo"); // connect to the red5 server}]> </FX: SCRIPT> <FX: declarations> <! -- Place non-visualelements (e.g ., services, value objects) Here --> </FX: declarations> <mx: hdividedbox x = "194" Y = "68" width = "750" Height = "430" fontsize = "16" fontweight = "bold"> <s: panel Height = "421" width = "50%" Title = "Mv list"> <mx: dataGrid width = "100%" Height = "100%" dataprovider = "{songlist}" id = "showlist" Click = "showlist_clickhandler (event)"> <mx: columns> <mx: datagridcolumn headertext = "song name" datafield = "showname" width = "250"/> <mx: datagridcolumn headertext = "artist" datafield = "songer"/> <mx: datagridcolumn headertext = "link address" datafield = "filmname" visible = "false"/> </MX: columns> </MX: DataGrid> </S: Panel> <s: panel width = "350" Height = "419" Title = "Mv preview"> <s: videodisplay id = "videodisplay" x = "20" Y = "20" width = "100%" Height = "100%"/> </S: Panel> </MX: hdividedbox> </S: Application>

 

For some comments, see the code. Click the music video name on the left to play the video on the right. A picture is displayed:



PS: Forgive me. I am a loyal fan of you hongming, so some of the computers are hongming music videos, '(* ∩ _ ∩ *)′...


Okay, it's very late. I'm going to bed. It's here ,...


Original article, reproduced please indicate the source: http://www.dianfusoft.com/




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.