Wow, that was a very thorough answer and I learned a few things from reading it. Unfortunately, the videos are not on a streaming server - I'm sorry, I should have been clear about that. I didn't realize the term "buffer" technically only applies to true streaming media. So, what are my options to change the percentage/amount of the file that gets downloaded before the video starts playing when I am using the FLVPlayback component?
Thank you!
Main Topics
Browse All Topics





by: ranhellPosted on 2008-04-17 at 15:48:21ID: 21382081
// calculate the buffertime _br/n_bw)) ;
t);
if(n_br>n_bw){
var n_bt = Math.ceil(n_vLen-n_vLen/(n
}else{
var n_bt = 0;
}
n_bt += 3;
ns_video.setBufferTime(n_b
One of the most often overlooked aspects of deploying real-time streaming Flash Video is buffering. And when I say real-time streaming Flash Video, I mean any FLV file that is served from Adobe Flash Media Server, such as a hosted server on Influxis.com, or a Flash Video Streaming Service provider like Akamai or Limelight. Any URI starting with rtmp:, rtmps:, or rtmpt: is considered a real-time streaming Flash Video.
NOTE: If youre deploying Flash Video from a web server using HTTP, then the following discussion about buffering does not apply. The buffer of a progressive download Flash Video is the amount of the file that has downloaded and cached to the browser.
So, once youve decided to use real-time streaming (RTMP) in your Flash Video deployment scenario, you must consider the bitrate (or data rate) of the Flash Video, or FLV, content you will serve to your audience. An FLV file can be encoded with only one bitratetheres no such beast as a multibitrate (or MBR) Flash Video file, as there is with Windows Media or other popular streaming web video formats. You can create multiple versions of a Flash Video clip, encoding as many bitrates as you would like to make available to your audience, and use ActionScript to pick the right FLV file to serve to the end-user. But, thats another topic entirelylets get back to buffering.
Buffering real-time streaming video is a bit awkward with the Flash Player. Lets define what a buffer is. The buffer for a Flash Video clip is simply the amount of video content, in seconds, that has temporarily cached to the users computer from the Flash Media Server. You can set the buffer time to any value you want, with the NetStream.setBufferTime() method in ActionScript 2.0 (AS2) or the NetStream.bufferTime property in ActionScript 3.0 (AS3). If youre fond of using the FLVPlayback component (either AS2 or AS3), you can use the FLVPlayback.bufferTime property to also control the buffer time of a real-time streaming Flash Video clip.
Now let me be clear: the buffer time is the amount of video content in seconds to cache on the users computer or device before playback of the video can begin. The buffer time is not necessarily how long the user will have to wait until playback starts. For example, if you have a 500Kbps video stream and you set the buffer time of the stream to 3 seconds, then 1500 kilobits (equivalent to 187,500 bytes or 183 KB) of the FLV file needs to download and temporarily cache before the video can start to play. If you have a 1500Kbps connection speed to the Flash Media Server, then you have to wait for only one second before the video begins playback, because thats the amount of time it would take to buffer 3 seconds of 500 Kbps video. However, if you have a 100Kbps connection to the Flash Media Server, you would have to wait 15 seconds for the first three seconds of the Flash Video clip to buffer.
Now that you understand how the buffer mechanism works with respect to time, lets look at why the Flash Player manages the buffer with playback states. When you first set the bufferTime property (or call the NetStream.setBufferTime() method in AS2), the Flash Player waits to play the stream until that amount of video time has buffered into memory. Once it has, you can adjust the buffer time to a new value without necessarily interrupting current playback. (Actually, theres a neat technique called dual buffering well-documented by Fabio Sonnati on Adobe DevNet, but again, thats another topic of discussion.) The Flash Player will also attempt to buffer more video than youve requested with your buffer time, permitted that your connection speed can accommodate it. For example, if you set the bufferTime property to 10 seconds, the Flash Player may actually be try to buffer 20 seconds, adjusting the buffer between 10 and 20 seconds as the video plays. The bufferTime property, therefore, is simply the minimum amount of video time that must buffer to the Flash Player before playback can begin (or resume if the buffer has emptied).
Of course, theres some bad news for buffering in the Flash Player: anytime you seek or pause the Flash Video clip, the entire buffer is dumped. If youve thought that you could buffer the entire video clip for slow connection speeds, forget about itonce the user pauses or seeks the video (if those operations are indeed permitted by your playback controls), then the user has to wait all over again for the buffer to refill. This is just a fact of life (or FOL, in geek terminology) with the Flash Player. Even if youve buffered the content that is seeked to by the user, the buffer is dumped.
Ive made a BufferDisplay component (AS2) that you can use as a GUI to set the NetStream.bufferTime (or FLVPlayback.bufferTime) property at runtime. The component also monitors and displays the NetStream.bufferLength property. You can download a ZIP file of the FLA and AS files. Experiment with the working example below, changing the buffer time and seeking to new points in the video clip to see how the buffering process works.