Hi, I’m trying to make a preloader for the buffer for a 19MB video. I can trace everything, but the math won’t do.
Preloading the video itself is no problem. But what I want is to make a xx% preloader for the buffer of this video.
This is my code. I’ve made a 10ms timer to check the progress of the video.
var myTimer:Timer = new Timer(10);
myTimer.addEventListener(TimerEvent.TIMER, checkBytesLoaded);
function checkBytesLoaded(e:TimerEvent) {
// creating a var of the buffertime / total time
var bufferPercent:Number = ns.bufferTime / objInfo.duration;
// normally ns.bytesLoaded / ns.bytesTotal gives the outcome of 100%
var pctLoaded:Number = (ns.bytesLoaded / (bufferPercent * ns.bytesTotal)) * 100;
// the textbox should be filled with a number + %.
preload._loader.text = pctLoaded + "%";
if (pctLoaded>=100) {
startVideo();
preload._loader.text = "";
}
Tracing deliveres this:
bytesloaded = 19.813442
bufferTime = 45
objTotalTime = 93.333
bytesTotal = 19.813442
pctloaded = 814221503081318.8
So in theory, the function must act like this:
(ns.bytesLoaded / (ns.bufferTime / objInfo.duration * ns.bytesTotal)) * 100 = %
When the video is buffering, I can see my computer is downloading the buffer bytes (in MenuMeters) but the preloader is only showing a value when the buffer is full and the video is playing. When the buffering is being loaded, nothing happens with the preloader values.
If I change the pctLoaded into ns.bytesLoaded, I see the value go up when the buffer is loading. What is wrong with this script?