-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVirtualBufferedManager.js
More file actions
72 lines (63 loc) · 1.52 KB
/
VirtualBufferedManager.js
File metadata and controls
72 lines (63 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use strict";
define(function(){
// son role est de mimiquer le buffered des sources buffers
// Il gere ses infos grâce aux pieces qu'on lui signale comme telechargées
var VBM = function(){
this.parts = [];
this.infosparts = [];
this.buffered = [];
this.length = 0;
}
VBM.prototype.clear = function ()
{
this.parts = [];
this.infosparts = [];
this.buffered = [];
this.length = 0;
}
VBM.prototype.addPiece = function (piece){
this.parts.push(piece.idPiece);
this.infosparts.push(piece.segment);
var mini = Math.min.apply(null, this.parts);
var maxi = Math.max.apply(null, this.parts);
var st = this.infosparts[this.parts.indexOf(mini)].time;
this.buffered = [];
for(var i=mini; i<maxi; i++)
{
if( !this.infosparts[this.parts.indexOf(i+1)] && st!==null)
{
this.buffered.push({start : st, end : this.infosparts[this.parts.indexOf(i)].time + this.infosparts[this.parts.indexOf(i)].duration});
st = null;
}
else if (this.infosparts[this.parts.indexOf(i+1)] && st===null)
{
st = this.infosparts[this.parts.indexOf(i+1)].time;
}
}
this.buffered.push({start : st, end : this.infosparts[this.parts.indexOf(maxi)].time + this.infosparts[this.parts.indexOf(maxi)].duration});
this.length = this.buffered.length;
}
VBM.prototype.start = function(i)
{
try
{
return this.buffered[i].start;
}
catch(e)
{
return 0;
}
}
VBM.prototype.end = function(i)
{
try
{
return this.buffered[i].end;
}
catch(e)
{
return 0;
}
}
return (VBM);
});