PDA

View Full Version : netStream preloading


mpol777
05-10-2004, 03:41 PM
I must be spacing out. What I'm trying to do is get the percent loaded on a netStream load so I have control over when I kick off the play. Problem is with the following code bytesLoaded and bytesTotal both return as 0.

I don't want to use the setBufferTime method since that doesn't translate into how much is loaded and the size of the videos can vary greatly. So what am I missing here?



// attach front video
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);

checkFrontProgress = function(videoRef) {
debug("videoRef: "+videoRef);
fbl = videoRef.bytesLoaded;
fbt = videoRef.bytesTotal;
debug("Loaded: "+fbl);
debug("Total: "+fbt);
fper = Math.floor(fbl/fbt*100);
if (fper >= 20) {
clearInterval(frontInterval);
videoRef.play(frontVideo);
}
}

frontViewVideo.attachVideo(ns);
frontInterval = setInterval(checkFrontProgress,100,ns);

mpol777
05-10-2004, 05:34 PM
I think I have this thing figured out. Below is a hack, but a working hack nonetheless. It turns out the pause() method toggles the play status. play() starts the whole thing over.


// attach front video
fnc = new NetConnection();
fnc.connect(null);
fns = new NetStream(fnc);
frontViewVideo.attachVideo(fns);

fns.play(frontVideo);
fns.pause();
preloaded = false;

function checkFProgress() {
fbl = fns.bytesLoaded;
fbt = fns.bytesTotal;
fper = Math.floor((fbl/fbt)*100);
debug(fper+"%");
if (fper >= 20) {
clearInterval(fInterval);
preloaded = true;
fns.pause();
}
}

fns.onStatus = function(infoObject) {
debug("Status (NetStream)");
debug("Level: "+infoObject.level);
debug("Code: "+infoObject.code);

if (!preloaded && infoObject.code == "NetStream.Play.Start") {
fInterval = setInterval(checkFProgress,100);
}
}