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