(reprint) AS3 httpclient read video stream information

Source: Internet
Author: User

HttpClient is frequently used in recent work.

First put on GitHub's project address Https://github.com/gabriel/as3httpclient

The principle is to use the socket to simulate an HTTP link to break through the various limitations of Flash Player

Because it is a socket connection, so the cross-domain problem people still have to pay attention to the next

such as referer that were not customizable in the original urlrequest.

Another beauty is that the original NetStream is not able to read the data to the stream,

Sometimes the data is hidden in the stream, and this class is used to solve the

This source is the search time to turn to the foreign technology, because the original link has been lost,

I can't afford to provoke a Russian fighting nation. I had to mark here I was reproduced =. -

1 Private varNs:netstream;2 Private varVideo:video;3 Private varMetaObject; 4 Private varclient:httpclient;5 Private varFileSize Number= 0; 6 Private varLoadedbytes: Number= 0; 7 Private varData:bytearray =NewByteArray ();8 Private varDatadelta: Number= 1024*1024; 9 Private varFile:string ="http://your_video_web_url/example.flv";Ten  One Private functionInit ():void{   A     varNsclient:Object= {};  -Nsclient.onmetadata =Metadatahandler; -     varNc:netconnection =Newnetconnection (); theNc.connect (NULL);  -NS =NewNetStream (NC); -Ns.client =nsclient; - Ns.addeventlistener (netstatusevent.net_status,netstatushandler); + Ns.addeventlistener (ioerrorevent.io_error,nsioerrorhandler); -Video =NewVideo (); + Video.attachnetstream (NS); AVideo.smoothing =true;  at uic.addchild (video); -Client =NewHttpClient (); - LoadData (); -Ns.play (NULL);  - }  - Private functionLoadData ():void{  in     varUri:uri =NewURI (file); -     varRequest:httprequest =NewGet (); to     varMaxdata Number= loadedbytes+Datadelta; +     if(Maxdata>=filesize and Filesize>0){  -Request.addheader (' Range ',' bytes= '+loadedbytes+'-');  the}Else {  *Request.addheader (' Range ',' bytes= '+loadedbytes+'-'+maxdata);  $     }Panax Notoginseng  -Client.listener.onData =function(e:httpdataevent):void  the     {  +         varBytes:bytearray =NewByteArray (); Abytes =e.bytes; thebytes.position = 0;  + data.writebytes (bytes); -     };  $  $Client.listener.onComplete =function(e:httpresponseevent):void{  -loadedbytes+=data.length; -FileSize = Number(E.response.header.getvalue (' Content-length '))/1024; the ns.appendbytes (data); - data.clear ();Wuyiinloaded =false;  the     };  -  Wu client.request (uri,request); -}

(reprint) AS3 httpclient read video stream information

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.