Tutorial – Playing FLV video in plain AS3 – Part 2

5 actionscript,as3,as3 tutorials,flash,work  |   June 10, 2008  |     2575

Hi Everyone,

today I will continue on this topic:

and the following installments are here:

In the first part I only discussed the essentials for playing an FLV. Today I will show how to build a re-usable class around those basic ideas. At the end of this tutorial you will have a solid set of classes (3) that you can reuse as a base to play FLV videos in all your widgets.

Architecture

There will be three classes involved in the development today:

  • MediaData — to hold the information on the FLV being played
  • FLVPlayer — to play the FLV
  • MediaEvent — to communicate with the outside world as to what is going on inside the FLVPlayer

This is a gross preview of where we are heading at:
diagram of FLVPlayer

MediaData
Will hold the basic information about the FLV to be played: it’s height, width, duration, uri, image to represent it, and title

FLVPlayer
Will play the actual FLV, using the MediaData object as input, and dispatch MediaEvent’s to inform the outside world of what is going on.

MediaEvent
Hold information to be received by the outside world, updating the status on what is happening in the FLVPlayer

MediaData

This is a simple class, whose role is simply to hold the information on a particular FLV file. It contains:

  • title — the title of the flv
  • image — an image to be used to represent the flv, either as a thumbnail or a place holder before the flv loads
  • uri — the uri of the FLV file itself
  • duration — the duration in seconds of the flv file
  • width — the width in pixels of the video
  • height — the height in pixels of the video

FLVPlayer

The FLVPlayer is the core where all the action happens. First let’s start with the most important functions:

  • connect() — to initialize the NetConnect & NetStream objects
  • playMedia(media:MediaData) — to start playing the media
  • pause() — to pause the media
  • seek(pos:Number) — to seek to a certain position

For an explanation of the code down here, please refer to the first part of the tutorial, which covers the basics. Note that if you want efficient loading of FLV’s one after the other, where it’s possible that the first one is not completely loaded yet when you want the second one to start playing (each new video replacing the old ones) it’s important to close the NetStream then the NetConnection, and start over with fresh ones (from my experience).

Now we can tackle the rest…

and finally the event handling function

finally the function to push a status code, and analyze the log

The rest is here: Tutorial – Playing FLV video in plain AS3 – Part 3

Comments
  • June 24, 2008 at 3:22 pm

    den

    great tutorial !!!

  • August 15, 2008 at 10:21 am

    art

    most comprehensive tutorial I have seen on this! any sign of a follow up?

  • September 16, 2008 at 6:57 am

    Andy

    Great tutorial, do you think you’ll have time to complete the next bit soon? 🙂

    Keep up the good work!

    Andy

  • September 27, 2008 at 2:03 pm

    Sven

    Will the tutorial on the Event class be finished?

  • November 2, 2009 at 6:50 pm

    Jingtao

    hello, everyone! I am making a flv video player.I want to complete that click anwhere then play at the position but not care if the position in the buffered scope, I use NetStream.seek(minute), but this only userfull int the buffered scope, can anyone help me? thanks .

Leave a Reply