tadalafil what is itcialis 20mg reviewgeneric tadalafil onlinebuy cheap tadalafil softbuy cialis online canadatadalafil dosecialis syntropbillig tadalafilcialis 2.5 mg cost walmartfree cialisprice compare tadalafilcialis romaniageneric cialis next day deliverycialis 20 mg onlinecialis dosage 40 mgtadalafil in pulmonary hypertensioncialis superactivepurchase cialis without prescriptioncialis dosage optionsgeneric tadalafil reviewcialis prices in mexicoguaranteed erections samplesgeneric cialis any goodgeneric cialis legalcheap tadalafil 20 mg onlinecialis pill cuttertadalafil 10mgcialis 5cheapest cialis ukbest discount cialisstallions erectionshow much cialiscialis side effectscheap 40 mg tadalafil visahow much does cialis costgeneric cialis usatadalafil pricecialis generiquebuy cialis 5mgcialis fast deliverytadalafil salecialas samplestadalafil professionaltadalafil tadalafilocialis paypal paymentpay with paypal for cialistadalafil dosingadcirca vs cialisgeneric cialis professionalcialis dealscialis coupon5mg cialisbuy cialis onlinecialis every daycanada brand name cialas 100mgcialis online canadian pharmacytadalafil daily dosecialis daily costsildenafil vardenafil tadalafilwhat is tadalafil 20mgvardenafil vs tadalafilcialis en francaiscialis professional reviewpaypal cialisfemale cialiswal-mart cialis pricetadalafil instructionsgeneric online cheap tadalafilcialis 5mg reviewscialis daily canadacheap cialis australiacialis online paypalcanadian everyday cialiscialis online canada no prescriptioncialis tadalafil lillycialas vancouver bcsildenafil or tadalafilcialis weekendgeneric cialis softbuy generic cialis canadapurchase cialis in mexicocialis professional canadatadalafil soft tabs 20mgcialis bestellendaily cialis 5mg genericcheap cialis from indiacialis chicagocialis online consultationgeneric verses traditional cialiscialis now no prescriptioncialis super active from indiabuy cialis online with a prescriptioncialas savingscialis price in mexicocialis super activegeneric cialis australiageneric cialis 20mg best buy mexicoorder cialiscialis no prescription needed candiancialis masturbationsildenafil vs tadalafil vs vardenafilcialis price comparisoncialis 2.5 prices canadatadalafil sublingual tabletswalgreens cost of cialistadalafil from canadageneric cialis capsuleswhat does generic cialis look likegeneric cialis online without prescriptioncialis without prescription in canadacialis price increasecanadian pharmacy cialiscialis 5mg daily dosecialis is awesomecialis 50 mgtadalafil soft tabsgeneric online order tadalafil 20mgfree cialis couponcialis generic canada drugstadalafil 20mgchemical makeup of cialisgeneric online order cheap tadalafil 20mgcialis online in canadacialas overmightcheap 40mg tadalafil overnight deliverytadalafil salecialis free sample canadacialis directionsis cialis covered by medicarecialis 20mg effectscialis vs viagra pricewhere to purchase cialistadalafil 5 mgcheapest tadalafil pharmacy comparisoncialis 5mg costcheap cialis soft tabscialis kontraindikacijeCialis discountcialis dosage side effectstadalafil bulkgeneric cialis in usacialis made in switzerlandcialis srbijageneric cialis clipsgeneric cialis namescheap cialis tabletscialis cenacanada cialistadalafil jellycialis price in indiacialis expiration datetadalafil maximum dosagecialis online canadacialis soft tabs 20mgtadalafil ohne rezeptis generic cialis availablecan cialis be bought over the countertadalafil pharmacokineticsis tadalafil the same as cialishow long does cialis 20mg lasttadalafil 100mglow dose cialis dailycialis from canadacialis for sale in ukcheap tadalafil for saleorder cheap tadalafilcialis online paypal paymentcialis netherlandscialis in canadacialis pill splittingtadalafil usacialis professional vs cialistadalafil tablets genericcialis vs over the countersildenafil tadalafil and vardenafiltadalafil effect on womenbuy tadalafil canadapurchase cheap cialis soft tabscialis price philippinegeneric tadalafil 10mghow to make cialis more effectivetadalafil 40 mgtadalafil costgeneric cialis 20mgbuy online cheap tadalafilgeneric tadalafil canadatadalafil tabletscialis expensivecompare generic cialis pricesventa de tadalafiltadalafil how long does it lastbest price for cialiscialistcialis 100cialis 20mg ukorder cheap cialis without prescriptioncheap brand tadalafilcost of cialis at walgreenscialis generique canadacialis canada cheapcialis 5mg dailylowest price tadalafilwhat is tadalafil oral jellycialistadalafil ukpurchase cialis online without prescriptioncialis price south africacialis 20 mg dailycialis francaiswhat does cialis look likegenetic tadalafilgeneric cialis in australiacialis 20 mg side effectscialis manilais tadalafil dangerouscialis cost australiaorder cialis from canadacialis 20tadalafil shelf lifepay with paypal for cialiscialis 10 mgfemale cialis reviewtadalafil tachyphylaxisorder cialis in canadatadalafil generic cialiswoman cialischeap cialis pricesgeneric cialis safetytadalafil pulmonary arterial hypertensionfemale cialis reviewsfree cialis samplesdoes female cialis worktadalafil for womencialis plustadalafil low dosebuy tadalafil 20mgmake cialis more effectivecialis retail price germanytadalafil how to usecialis vs cialis professionalcialis brandbuying cialis online reviewtadalafil intermediatescialis professional informationgeneric cialis overnightcialis saletadalafil erectile dysfunctiongeneric cialis free samplecialis 3 daycialis 40 mg dosetadalafil 10mg supplierlowest price cialistadalafil soft softcialis tablets for saletadalafil tolerancecialis pillscialis 20 mg reviewscialis efectos secundarioscialis sydneypurchase cialis without a prescriptionvardenafil tadalafiltadalafil from indiasuper active cialiscialis online in australiacialis couponstadalafil for pulmonary hypertensiontadalafil chewable tabletstadalafil womentadalafil pahtadalafil online without prescriptioncialis home deliverytadalafiltadalafil soft tablets 20mgtadalafil vardenafilcialis canada pricecialis 5 mg onlinecialis lelongcialis gel tabscialis c20tadalafil ranbaxycialis soft tabs reviewcialis cost ontariocialis soft tabs dosagetadalafil buy cheap onlinecialis srpskicialis online irelandcheapest cialis onlineprice of cialiscialis mail ordercan you buy cialis without a prescriptioncialis colombiacheap no prescription tadalafiltadalafil price comparisonbuy cialis with paypalcialis over the counter in montrealcialis cost walgreenscialis for salegeneric cialis online pharmacytadalafil generic uktadalafil 20mg indiafree cialis trialcost of 5mg cialiscialis irelandcialis samples in canadatadalafil medicationgeneric cialis indiatadalafil nedirtadalafil 20mg sx oral jelliestadalafil maximum dosebuy cialis online australiacialis 5mg side effectscialis no perscription paypalcialis online paypal canadacialis tabletshow effective is combining of injection medication with 20mg of cialasfast delivery cialas onlinetadalafil softcialis cost walmartcialis trial offertadalafil user reviewsbuy cialis online cheapcialis-savings.comcheap cialis pillscialis original buy onlinecialis once a day pricingcialis online pharmacythe effects of cialis on women does cialis work on womentadalafil msdscialis price paypaltadalafil long termcialis 5mg canadatadalafil usescialis without prescription in canadadaily cialiscialis price ukcialis 5mgtadalafil pulmonary hypertensioncialis goldgeneric cialis daily usetadalafil other usesone a day cialis reviewscialis beogradcialis online prescriptiontadalafil citrate dosagetadalafil e20cialis every day pillgeneric cialis no prescriptiongeneric cialis in ukcialis in costa ricacheap 10 mg tadalafil with amextadalafil generic alternativecheap 40 mg tadalafil otccialis price ustadalafil tablets 20mgbuy cialis from canadahow long does cialas 5mg take to worktadalafil half lifecomprar tadalafilcialis 10mg pricecheapest cialis pricestadalafil canadawhere can i buy cialis online without a prescriptioncialis for lowest price in canadaliquid tadalafilhow much is cialiscialis online discounttadalafil ic-351 25 mg mlcialispaypalcialis in costa ricabuy cheap cialis ukwhat dose of cialis should i takebuy tadalafil best pricetadalafil pharmacologycialis online pharmacy canadatadalafil package insertcialis online couponcialis 10mgdaily cialis 5mg pricecheap tadalafil 5 mg with amexcheap 5 mg tadalafilgeneric cialis reviewsgeneric cialis viagrabuy cialis in mexicoorder tadalafil onlinecialis price canadaonline order tadalafilcialis cost comparison walgreens and walmartgeneric cialis 10mgdiscount tadalafilcialis germanycialis in chennaicialis pay with pay palovernight cialisbuy cialis soft tabshow long does it take for cialas to workcialis tadalafil 10mgcialis daily dose costcialas compared to viragacialis 5mg tabletsorder cialis without a prescriptionshoppers drugmart cialis costtadalafil tablets for womengeneric cialis 40 mgtadalafil blogcialis 40mgbuy cialis online usacialis for womengeneric cialis best priceonline cheap tadalafil 20mgcialis canada onlinecialis overnight deliverytadalafil online canadacialis brand onlinecialis 20 mg lillyis generic tadalafil safecheap cialisorder cialis online without prescriptioncialis 40 mg erection after ejaculationorder cialis online with prescriptioncialis genericcheap tadalafil 40 mg with mastercardcialis professional online2.5mg cialistadalafil citrate liquidcialis price australiacialis professionalcialis india pharmacywhere to buy cialis without prescriptiontadalafil synthesiscialis free trialcanada/cialischeap canadian cialiscialis professional tadalafiltadalafil ciplawalmart prescription price for cialiscialis one a daycialis c10cheap cialis 20mgcialis super active reviewsoffshore drugs cheap tadalafilaverage cost cialiscialis100mgcialis 10mg vs 20mgbuy cialis online from canadacialis tabs 20mggeneric cialis online canadatadalafil directionsgeneric cialis from canadacheap cialis 5mggeneric cialis safewho makes cialiserection time shortcialis super active 20mg pricebuy cialis online paypalcialis from turkeycheap sildenfil with 4 free tadalafiltadalafil vs viagracialis dosage sizecialis 2.5mgbuy cialis australiageneric tadalafil 20mggeneric cialis buytadalafil forumcheap 5 mg tadalafil with amextadalafil on nhstadalafil dailytadalafil alternativetadalafil timecialis online without prescriptionbest price on brand cialistadalafil online pharmacycheap 20 mg tadalafil visacheap tadalafil generic mastercardcialis over the counterbest price on cialis for daily useno prescription tadalafilgeneric cialistadalafil effectivenesstadalafil mechanism of actiontadalafil interactionsbuy generic tab tadalafilcialis nyccialis paypalcialis 20mg side effectslow price tadalafilbuy cialis canadastreet price of cialiscan cialis and viagra be taken togethercialis instructionscialis 5mg vs 20mgcheap cialis in australiacialis shelf lifecialis free trial canadadiscount cialis canadacipla tadalafil reviewbuy cialis online in usabuy cialis online without a prescriptiontadalafil for saleonline cialis pay with paypalcialis dosage levels
intense creativity » Tutorial - Playing FLV video in plain AS3 - Part 1

Tutorial - Playing FLV video in plain AS3 - Part 1

Hi Everyone,

today I will explain how to play .FLV files that are hosted on a standard HTTP server, no fancy streaming. You can use pre-made components to do so, but sometimes, for whatever reason, you want to do it yourself. I wrote my first FLV playing algorithm in AS3 about 10 months ago, it has evolved since and here is the breakdown on how I make it work. It's been used in many widgets, mostly for Music Nation.

Objects we will play with

There are a number of objects available in the standard AS3 library that is included with both Flash CS3 and Flex. Here is a list of those we will be using, along with a point form explanation of what we will use them for

  • flash.net.NetConnection -- to establish the connection to the HTTP server
  • flash.net.NetStream -- to "stream" or download the media from the HTTP server
  • flash.media.SoundTransform -- to modify the volume at which the FLV is playing
  • flash.media.Video -- this holds the visual representation of the video

This being said, we will also have to catch quite a few potential errors, here is the list of error events we will deal with

  • flash.events.SecurityErrorEvent -- on NetConnection
  • flash.events.IOErrorEvent -- on NetConnection AND NetStream
  • flash.events.AsyncErrorEvent -- on NetStream

And finally we will use the flash.net.NetStatusEvent on both the NetStream and the NetConnection to keep track of what is happening.

First bit of code..

I will start with the basics..

Actionscript:
  1. var connection:NetConnection;
  2. var stream:NetStream;
  3. var video:Video;
  4.  
  5. // first let's create the NetConnection
  6. connection = new NetConnection();
  7.  
  8. // let set it to HTTP "streaming" mode, the null is to specify we are NOT connecting to a media server
  9. connection.connect(null);
  10.  
  11. // now let's create the NetStream
  12. stream = new NetStream(connection);
  13.  
  14. // the set it's client to receive certain events
  15. stream.client = this;
  16.  
  17. // create a video object, set it to 425x320 as default size, this holds the visual representation of the video
  18. var video:Video = new Video(425, 320);
  19.  
  20. // add it to the stage
  21. stage.addChild(video);
  22.  
  23. // attach the NetStream to the video object
  24. video.attachNetStream(stream);
  25.  
  26. // let's set the default buffer time to 1 second
  27. stream.bufferTime = 1;
  28.  
  29. // tell the stream to receive the audio
  30. stream.receiveAudio(true);
  31.  
  32. // tell the stream to receive the video
  33. stream.receiveVideo(true);
  34.  
  35. // play a FLV file on a HTTP server
  36. stream.play("http://www.yourhost.com/myvideo.flv");

That's it. With this code, you'll be playing a FLV file on the Stage. No controls yet...

The MetaData

This line of code

Actionscript:
  1. stream.client = this;


enables the object ("this" in this case) to receive special information about the playing Stream. You need to implement functions to catch that information, namely: onMetaData, onCuePoints, onPlayStatus. In the case of playing .FLV's off an HTTP server, the onCuePoints and onPlayStatus are completely useless.

There are a number of things that are important about an FLV file that is playing, which are both received when the FLV starts loading:

  • video size in pixels
  • actual duration of the FLV in seconds

Here is how you catch it:

Actionscript:
  1. public function onMetaData(infoObject:Object):void
  2. {
  3.      if(infoObject.duration != null)
  4.      {
  5.           trace("our video is "+infoObject.duration+" seconds long");
  6.      }
  7.  
  8.      if(infoObject.height != null && infoObject.width != null)
  9.      {
  10.           trace("our video is "+infoObject.height+"x"+infoObject.width+" pixels");
  11.  
  12.           // here you want to resize your video object to match there dimensions
  13.           video.height = infoObject.height;
  14.           video.width = infoObject.width;
  15.           // for example
  16.      }
  17. }

Handling Events & Errors

Both the NetStream and NetConnection objects throw errors.

Actionscript:
  1. // on the NetConnection
  2. connection.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
  3. connection.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
  4. connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doSecurityError);
  5.  
  6. // on the NetStream
  7. stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
  8. stream.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
  9. stream.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
  10.  
  11. protected function doSecurityError(evt:SecurityErrorEvent):void
  12. {
  13.     trace("AbstractStream.securityError:"+evt.text);
  14.         // when this happens, you don't have security rights on the server containing the FLV file
  15.         // a crossdomain.xml file would fix the problem easily
  16. }
  17.        
  18. protected function doIOError(evt:IOErrorEvent):void
  19. {
  20.     trace("AbstractScreem.ioError:"+evt.text);
  21.         // there was a connection drop, a loss of internet connection, or something else wrong. 404 error too.
  22. }
  23.  
  24. protected function doAsyncError(evt:AsyncErrorEvent)
  25. {
  26.     trace("AsyncError:"+evt.text);
  27.         // this is more related to streaming server from my experience, but you never know
  28. }
  29.  
  30. protected function doNetStatus(evt:NetStatusEvent):void
  31. {
  32.     trace(evt.info.code);
  33.         // this will eventually let us know what is going on.. is the stream loading, empty, full, stopped?
  34. }

ok that's it for today, I will write part 2 tomorrow or the next day. In part two I will cover the trickier stuff, tracking the loading progress, enabling play/pause/stop, canceling the loading process of a FLV, seeking to a certain position, tracking the position of the stream and finally knowing exactly when the FLV is done playing!

Cheers!



Related posts (automatically generated):

  1. Tutorial - Playing FLV video in plain AS3 - Part 2
  2. Tutorial - Playing FLV video in plain AS3 - Part 3 (Updated)
  3. Tutorial - Playing FLV video in plain AS3 - Part 4 - Sample Usage


11 Responses to “Tutorial - Playing FLV video in plain AS3 - Part 1”

  1. Giannis T. says:

    Thank you for a really enlightening articles series!

  2. Jack says:

    Hey,

    Thank you so much for putting these tutorials online. You are an invaluable help to peoples understanding of ActionScript.

    I followed the tutorial and everything was working fine until I set up the Security/Error/NetStatus functions. It then stated that an instance was null and would not compile the file. I built a class for this and attached it to the Fla through the Document class. I imagine that in the next 2 tutorials it will clear up.

    Thanks for all your incredible help. I in turn, will set up the same kind of blog when I get to your level to help people out like you helped me.

    Why would it do that?

  3. Raman says:

    This tutorial is excellent .

    I want to create flv player with all the functionalities but
    want that playing video to be manged by user.
    i.e suppose if our video is 2 min long and user wants to view a part of video from timings 1min to 1min 30 sec ..
    how can we do that

  4. Mark says:

    Nice tutorial, but where do you call the onMetaData function? I don’t get the trace of the function in my output? I’ve tried to use a client object, but that didn’t work.

    //

    _client = new Object();

    _stream = new NetStream(_connection);
    _stream.client = _client;

    _client.onMetaData = onMetaData;

    //

    Thank you for responding!
    Mark

  5. dbam says:

    I’m really thankful for this collection on FLV playback error-handling.
    Extremely HAND(L)Y!

    Have a good day.

  6. Rowan Gray says:

    I’ve just nabbed your code because my own FLV player is aweful, I did intend to recode it, but your player here is so beautifully coded I’m just going to use that and
    add on bits if I need extra functions.

    Thank you.

  7. Rowan Gray says:

    should add:

    public function onXMPData(infoObject:Object):void { }

    to FLVPlayer, to silence the onXMPData error ;)

  8. legris says:

    [...] As part of our anti-spam campaign, please input the text you see in this image (required) …intense creativity Tutorial - Playing FLV video in plain …today I will explain how to play .FLV files that are hosted on a standard HTTP server, no … You [...]

  9. charles says:

    good utorial.
    i am looking forward to get my hands on the next part.

  10. charles says:

    good tutorial.
    i am looking forward to get my hands on the next part.

  11. Germo says:

    Thanks this tutorial, much easy to use than origin description in help.

Leave a Reply