Tutorial – Playing FLV video in plain AS3 – Part 4 – Sample Usage

6 actionscript,as3,as3 tutorials,flash  |   December 11, 2009  |     2923

Hi Everyone..

This is the fourth (and most probably the last) installment of this series on playing FLV (and H.264 MP4) video in Flash from scratch.

Full source code for the library is here.

The related posts are:

For many of you, this might be the only post you are interested in. It will show you how to use the library.

Let’s start with the basics, or if you prefer, the essentials ;). Download the source which is here. Unzip it into your classpath, then create a new ActionScript class (I suggest FlashDevelop or for those who can deal with Eclipse (i can’t) Flex Builder). Comments are in the code.

List of Events
Now this is good, the video is playing, let’s look into the events generated by the FLVPlayer class. Their name is meant to be descriptive enough, and here is the full list:

  • MediaSizeEvent.SIZE — dispatched when the dimensions in pixels of the video is received
  • MediaEvent.STARTED_PLAYING — dispatched when the video starts playing
  • MediaEvent.FINISHED_PLAYING — dispatched when the video finished playing
  • MediaTimeEvent.DURATION — dispatched when the duration (seconds) of the video is received
  • MediaTimeEvent.TIME -- dispatched a few times a second to update the current position of the video
  • MediaEvent.ERROR — dispatched when an error is found while playing

Handling each event
First we need to update the initEvents function to add event listeners for each event…

This event carries with it the dimensions in pixels of the FLV or MP4 file. It can be used to resize the Video object accordingly, either stretching to specific dimensions while maintaining aspect ratio, or fitting it exactly.

These two events simply indicate when the media starts and finishes playing. I don’t know what you want to do then, so I simply trace it to the output.

Honestly, I don’t think I use this event yet, but maybe in the future. So again just trace it..

This event contains the length in seconds of the media playing, in this case the FLV or MP4. This can be used to adjust your scrobbler bar.. for example, or to display in a textfield somewhere.

This event keeps you posted as to the progress of the position inside of the media. This can also be used to update your Scrobbler bar, or textfield.. It is dispatched 4 times per second, no matter how slowly or fast the media is playing.

Other useful functions
You can also explore certain functions, which are rather straightforward; such as:

  • pause
  • play
  • mute
  • setVolume
  • mute
  • seek
  • stop
  • close
  • reset



  • April 19, 2010 at 4:24 pm


    How does one implement a stop button in this program? When I try, the video disappears but the audio continues playing.

  • May 18, 2010 at 3:54 am


    How to find out the progress? the position only gives me the time ? 🙁

  • September 3, 2011 at 12:59 am

    Puscasu Razvan

    If i int 2 videoPlayers and play them .


    The videos have a few seconds delay i would like them to start at the same time.


  • September 4, 2011 at 4:57 pm


    Puscasu, I suggest loading both videos (playMedia), and pause them right away so they don’t start, then catch the media_ready event (I forget the exact name, I coded that thing 3 years ago!) and then start both of them at the same time. The delay is cause by Flash, not my code. Loading videos is resource intensive…

  • April 26, 2012 at 5:55 am

    Deepu George jacob

    Resume is not implemented on this tutorial

  • June 26, 2012 at 3:31 am


    I am new to flash and AS.
    I am using your source code to play the FLV. I am using camera before starting FLV video.
    My problem is that the camera view coming over the FLV Video which palying in background.
    I need the FLV on over the camera view so that transparent FLV video will come over the camera view.
    How can i do this ?

    Thank you.

Leave a Reply