forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcalculateBufferPercent.as
More file actions
23 lines (20 loc) · 1.1 KB
/
calculateBufferPercent.as
File metadata and controls
23 lines (20 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package utils.load
{
import utils.math.Percent;
import utils.number.clamp;
/**
Calculates the percent the video has buffered.
@param bytesLoaded: Number of bytes that have loaded between <code>startTime</code> and <code>elapsedTime</code>.
@param bytesTotal: Number of bytes total to be loaded.
@param startTime: Time in milliseconds when the load started.
@param elapsedTime: The current time in milliseconds or time when load completed.
@param lengthInMilliseconds: The total duration/length of the video in milliseconds.
@return The percent buffered.
*/
public function calculateBufferPercent(bytesLoaded:uint, bytesTotal:uint, startTime:uint, elapsedTime:uint, lengthInMilliseconds:uint):Percent
{
var totalWait:Number = bytesTotal / (bytesLoaded / (elapsedTime - startTime)) - lengthInMilliseconds;
var millisecondsRemaining:uint = calculateMillisecondsUntilBuffered(bytesLoaded, bytesTotal, startTime, elapsedTime, lengthInMilliseconds);
return (totalWait == Number.POSITIVE_INFINITY) ? new Percent(0) : new Percent(clamp(1 - millisecondsRemaining / totalWait, 0, 1));
}
}