forked from lopezs/ableplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.js
More file actions
66 lines (60 loc) · 1.73 KB
/
metadata.js
File metadata and controls
66 lines (60 loc) · 1.73 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
(function ($) {
AblePlayer.prototype.updateMeta = function (time) {
if (this.hasMeta) {
this.$metaDiv.show();
this.showMeta(time || this.getElapsed());
}
};
AblePlayer.prototype.showMeta = function(now) {
var m, thisMeta, cues;
if (this.meta.length >= 1) {
cues = this.meta;
}
else {
cues = [];
}
for (m in cues) {
if ((cues[m].start <= now) && (cues[m].end > now)) {
thisMeta = m;
break;
}
}
if (typeof thisMeta !== 'undefined') {
if (this.currentMeta !== thisMeta) {
// it's time to load the new metadata cue into the container div
this.$metaDiv.html(this.flattenCueForMeta(cues[thisMeta]).replace('\n', '<br>'));
this.currentMeta = thisMeta;
}
}
else {
this.$metaDiv.html('');
this.currentMeta = -1;
}
};
// Takes a cue and returns the metadata text to display for it.
AblePlayer.prototype.flattenCueForMeta = function (cue) {
var result = [];
var flattenComponent = function (component) {
var result = [];
if (component.type === 'string') {
result.push(component.value);
}
else if (component.type === 'v') {
result.push('[' + component.value + ']');
for (var ii in component.children) {
result.push(flattenComponent(component.children[ii]));
}
}
else {
for (var ii in component.children) {
result.push(flattenComponent(component.children[ii]));
}
}
return result.join('');
}
for (var ii in cue.components.children) {
result.push(flattenComponent(cue.components.children[ii]));
}
return result.join('');
};
})(jQuery);