Public classMinistreamextendssprite{Private var_buffer:bytearray =NewByteArray (); Private var_ns:netstream; Private var_nc:netconnection; Private var_video:video; Private var_TC: Number= 0; Private var_ustream:urlstream; Private var_elapsed_bytes:uint = 0; Public functionMinistream (onvideo:function) {_video=NewVideo (400,300); AddChild (_video); _ustream=NewURLStream (); _ustream.addeventlistener (Ioerrorevent.io_error, Onerr); _ustream.addeventlistener (progressevent.progress, onprogress); } Public functionPlay ():void{_NC=Newnetconnection (); _nc.connect (NULL); if(_ns) {_ns.removeeventlistener (netstatusevent.net_status, onstatus); } _ns=NewNetStream (_NC); _ns.addeventlistener (Netstatusevent.net_status, onstatus); _ns.client= {}; _ns.buffertime= 3; _video.attachnetstream (_ns); _ns.play (NULL); _ns.appendbytesaction (Netstreamappendbytesaction.reset_begin); _ns.addeventlistener (Netstatusevent.net_status, Netstatushandler); _ustream.load ("http://example.com/h264vid.flv"); } Private functionOnstatus (e:netstatusevent):void{trace (e.info.code); } Private functionOnProgress (e:progressevent):void { //stores in our BA buffer_ustream.readbytes (_buffer,0, _ustream.bytesavailable); _buffer.position= 0; if(_buffer.bytesavailable > 0) {_ns.appendbytes (_buffer); _elapsed_bytes+=_buffer.length; _buffer.clear (); } } Private functionNetstatushandler (evt:netstatusevent):void { if(Evt.info.code = ="NetStream.Play.Stop") {_ns.appendbytesaction (netstreamappendbytesaction.end_sequence); }} Private functionOnerr (e:ioerrorevent):void { //Trace ("ERROR", e.text); }}
Play flv with NetStream's appendbytes