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:
MediaTimeEvent.TIME -- dispatched a few times a second to update the current position of the video
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.
MediaEvent.STARTED_PLAYING & MediaEvent.FINISHED_PLAYING
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:
How does one implement a stop button in this program? When I try, the video disappears but the audio continues playing.
How to find out the progress? the position only gives me the time ?
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.
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…
Resume is not implemented on this tutorial
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 ?