Is this even possible? I'm using Flash 8 AS 2 and am playing progressive video files that are quite long. I'm able to calculate an ideal buffer time based on the flv length, flv bit rate and available bandwidth, and would also like to provide the user some feedback as the buffering is taking place before the video begins to play.
I was able to accomplish this using a Video object and then creating NetConnection and NetStream Objects in AS that are associated with it. This way I can use the NetStream object's "bufferLength" and "bufferTime" values to calculate how much of the buffer has been loaded so far. Something like this:
var connection_nc:NetConnectio
n = new NetConnection();
connection_nc.connect(null
);
var stream_ns:NetStream = new NetStream(connection_nc);
my_video.attachVideo(strea
m_ns);
// Calc buffer time needed
stream_ns.setBufferTime( BufferCalculator.calculate
(flvLength
, flvBitrate, bandwidth) );
txtPercent.text = "0%";
var buffer_interval:Number = setInterval(checkBufferTim
e, 50, stream_ns);
function checkBufferTime(my_ns:NetS
tream):Voi
d {
// Calc percentage buffered
var bufferPct:Number = Math.min( Math.round(my_ns.bufferLen
gth/my_ns.
bufferTime
*100), 100);
// Buffering complete
if( bufferPct == 100 ){
txtPercent._visible = false;
txtBuffering._visible = false;
clearInterval(buffer_inter
val);
}
else{
txtPercent.text = bufferPct + "%";
}
}
I've been trying to do the same thing using the FLVPlayback component instead, but I can't find any way to expose the NetStream object associated with the FLVPlayback to get the "bufferLength" value. Is this possible or is there a better way to accomplish this?
Start Free Trial