Jump to content
Search Community

Checking for download speed and changing stuff?

Nickbee test
Moderator Tag

Recommended Posts

I'm working on a rotating video header. The idea is that videos will be the priority unless they take too long to download. If so that "profile" will be switched to a low speed profile that loads images instead.

 

I have the logic working, but I want to be sure I'm checking the speed the best way possible.

 

If a video is not loaded a loaderBar is displayed. At the same time the progress handler is checking the time left to download. If that time goes above a certain number (_maxVideoLoadTime) it kicks things over to a lowSpeed profile....

 

private function videoLoadingBarProgressHandler(evt:LoaderEvent):void
	{
		var pcent:Number = Math.ceil((evt.target.progress)*100);
		_preLoader.progress_mc.scaleX = pcent/100;
		_preLoader.text_txt.text = pcent + "%";

		//calculate time left
		if(evt.target.progress != 0)
		{
			var SecondsLeft:uint = Math.ceil(((1 / evt.target.progress) - 1) * evt.target.loadTime);
			var string:String = new String(SecondsLeft);
			timeLeft.text = "secLeft: " + string;

			if (SecondsLeft > _maxVideoLoadTime)
			{
				trace("*********** SWITCH TO LOW SPEED ****************");
				_highSpeedLoader.pause();
				initLowSpeedLoader();
			}
		}
	}

 

Suggestions would be great if this is not the best way to accomplish this.

 

THANKS!

Link to comment
Share on other sites

OK, now that I've tested this at home I see there's a flaw to my logic.

 

Even though a video might download in less than 6 seconds there is that initial period where the seconds left might be very high (until things get moving after the 1st bit of downloading).

 

So what if i changed

if(evt.target.progress != 0)

 

to something like

if(evt.target.progress > .10)

 

then my script to switch to the slow speed profile wont start working until 10% of the file is downloading and things are moving.

 

BTW, I am using estimatedBytes in these loaders.

 

Thanks for any feedback!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...