Flex Intelligent Video Buffering Component – Part 1
Recently at work I have been working on a project which involves streaming large amounts of video using progressive download. If you use Flash Media Server (has a new name now doesn’t it?), then it will automatically figure out how large the video buffer should be for you, but I wanted to implement the same functionality for progressive downloads within a flex component.
To determine the correct buffer size, you need three bits of information:
- The available bandwidth that the user has
- The size of the video to be played, and
- The bitrate of the video to be played
The user’s bandwidth can be detected fairly easily. In the example application below, the code simply times how long it takes to download the image show at the top right of this post, which is a 150 KB file. This gives a crude estimation of the user’s connection speed which is good enough for my purposes.
Click on image to view the applicaiton, right click on the application to view source.

The size of the file can be detected easily by getting a reference to the loader object which is retrieving the file. The bytesTotal property gives the total size of the file in bytes.
That just leaves the bitrate of the video file. This information is contained within the metadata on the FLV file, and is used by flash to display the video correctly. I have looked long and hard though the Flex documentation and source code, and I cannot find a way to get this information at all. It did occur to me that maybe I could divide the number of bytes in the file by the length of the video in seconds, and this might give a ‘good enough’ answer. It does still feel like a bit of a hack to me though.
I’m hoping that someone who reads this will be able to give me some adive for my problem. Does anyone know how to get the bitrate of a FLV file programatically? Or is dividing the file size by the length of the video the way to go? Any advice would be much appreciated.
If someone can help me out, I’ll hopefully post my finished buffering video control at the end of the week.
Get Your 15 Minutes of Fame »« Flash Player 9 – 2,320,000,000 installs!