Skip to content

Commit 561f8df

Browse files
committed
Improve support for metadata tracks
1 parent 98fc2a8 commit 561f8df

14 files changed

Lines changed: 356 additions & 69 deletions

build/ableplayer.dist.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@
197197
this.forceLang = true;
198198
}
199199

200+
if ($(media).data('meta-type') !== undefined && $(media).data('meta-type') !== "") {
201+
this.metaType = $(media).data('meta-type');
202+
}
203+
200204
if ($(media).data('meta-div') !== undefined && $(media).data('meta-div') !== "") {
201205
this.metaDiv = $(media).data('meta-div');
202206
}
@@ -4074,17 +4078,24 @@
40744078
};
40754079

40764080
AblePlayer.prototype.setupMetadata = function(track, cues) {
4077-
// NOTE: Metadata is currently only supported if data-meta-div is provided
4078-
// The player does not display metadata internally
4079-
if (this.metaDiv) {
4080-
if ($('#' + this.metaDiv)) {
4081-
// container exists
4082-
this.$metaDiv = $('#' + this.metaDiv);
4083-
this.hasMeta = true;
4081+
if (this.metaType === 'text') {
4082+
// Metadata is only supported if data-meta-div is provided
4083+
// The player does not display metadata internally
4084+
if (this.metaDiv) {
4085+
if ($('#' + this.metaDiv)) {
4086+
// container exists
4087+
this.$metaDiv = $('#' + this.metaDiv);
4088+
this.hasMeta = true;
4089+
this.meta = cues;
4090+
}
40844091
}
40854092
}
4086-
this.meta = cues;
4087-
}
4093+
else if (this.metaType === 'selector') {
4094+
this.hasMeta = true;
4095+
this.visibleSelectors = [];
4096+
this.meta = cues;
4097+
}
4098+
};
40884099

40894100
AblePlayer.prototype.loadTextObject = function(src) {
40904101

@@ -7223,13 +7234,18 @@
72237234
(function ($) {
72247235
AblePlayer.prototype.updateMeta = function (time) {
72257236
if (this.hasMeta) {
7226-
this.$metaDiv.show();
7227-
this.showMeta(time || this.getElapsed());
7237+
if (this.metaType === 'text') {
7238+
this.$metaDiv.show();
7239+
this.showMeta(time || this.getElapsed());
7240+
}
7241+
else {
7242+
this.showMeta(time || this.getElapsed());
7243+
}
72287244
}
72297245
};
72307246

72317247
AblePlayer.prototype.showMeta = function(now) {
7232-
var m, thisMeta, cues;
7248+
var m, thisMeta, cues, cueText, cueLines, i, line;
72337249
if (this.meta.length >= 1) {
72347250
cues = this.meta;
72357251
}
@@ -7242,15 +7258,45 @@
72427258
break;
72437259
}
72447260
}
7245-
if (typeof thisMeta !== 'undefined') {
7246-
if (this.currentMeta !== thisMeta) {
7247-
// it's time to load the new metadata cue into the container div
7248-
this.$metaDiv.html(this.flattenCueForMeta(cues[thisMeta]).replace('\n', '<br>'));
7261+
if (typeof thisMeta !== 'undefined') {
7262+
if (this.currentMeta !== thisMeta) {
7263+
if (this.metaType === 'text') {
7264+
// it's time to load the new metadata cue into the container div
7265+
this.$metaDiv.html(this.flattenCueForMeta(cues[thisMeta]).replace('\n', '<br>'));
7266+
}
7267+
else if (this.metaType === 'selector') {
7268+
// it's time to show content referenced by the designated selector(s)
7269+
cueText = this.flattenCueForMeta(cues[thisMeta]);
7270+
cueLines = cueText.split('\n');
7271+
for (i=0; i<cueLines.length; i++) {
7272+
line = $.trim(cueLines[i]);
7273+
if (line.toLowerCase() === 'pause') {
7274+
this.pauseMedia();
7275+
}
7276+
else {
7277+
if ($(line).length) {
7278+
// selector exists
7279+
$(line).show();
7280+
// add to array of visible selectors so it can be hidden at end time
7281+
this.visibleSelectors.push(line);
7282+
}
7283+
}
7284+
}
7285+
}
72497286
this.currentMeta = thisMeta;
72507287
}
72517288
}
7252-
else {
7253-
this.$metaDiv.html('');
7289+
else {
7290+
if (typeof this.$metaDiv !== 'undefined') {
7291+
this.$metaDiv.html('');
7292+
}
7293+
if (this.visibleSelectors.length) {
7294+
for (i=0; i<this.visibleSelectors.length; i++) {
7295+
$(this.visibleSelectors[i]).hide();
7296+
}
7297+
// reset array
7298+
this.visibleSelectors = [];
7299+
}
72547300
this.currentMeta = -1;
72557301
}
72567302
};

build/ableplayer.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@
197197
this.forceLang = true;
198198
}
199199

200+
if ($(media).data('meta-type') !== undefined && $(media).data('meta-type') !== "") {
201+
this.metaType = $(media).data('meta-type');
202+
}
203+
200204
if ($(media).data('meta-div') !== undefined && $(media).data('meta-div') !== "") {
201205
this.metaDiv = $(media).data('meta-div');
202206
}
@@ -4074,17 +4078,24 @@
40744078
};
40754079

40764080
AblePlayer.prototype.setupMetadata = function(track, cues) {
4077-
// NOTE: Metadata is currently only supported if data-meta-div is provided
4078-
// The player does not display metadata internally
4079-
if (this.metaDiv) {
4080-
if ($('#' + this.metaDiv)) {
4081-
// container exists
4082-
this.$metaDiv = $('#' + this.metaDiv);
4083-
this.hasMeta = true;
4081+
if (this.metaType === 'text') {
4082+
// Metadata is only supported if data-meta-div is provided
4083+
// The player does not display metadata internally
4084+
if (this.metaDiv) {
4085+
if ($('#' + this.metaDiv)) {
4086+
// container exists
4087+
this.$metaDiv = $('#' + this.metaDiv);
4088+
this.hasMeta = true;
4089+
this.meta = cues;
4090+
}
40844091
}
40854092
}
4086-
this.meta = cues;
4087-
}
4093+
else if (this.metaType === 'selector') {
4094+
this.hasMeta = true;
4095+
this.visibleSelectors = [];
4096+
this.meta = cues;
4097+
}
4098+
};
40884099

40894100
AblePlayer.prototype.loadTextObject = function(src) {
40904101

@@ -7223,13 +7234,18 @@
72237234
(function ($) {
72247235
AblePlayer.prototype.updateMeta = function (time) {
72257236
if (this.hasMeta) {
7226-
this.$metaDiv.show();
7227-
this.showMeta(time || this.getElapsed());
7237+
if (this.metaType === 'text') {
7238+
this.$metaDiv.show();
7239+
this.showMeta(time || this.getElapsed());
7240+
}
7241+
else {
7242+
this.showMeta(time || this.getElapsed());
7243+
}
72287244
}
72297245
};
72307246

72317247
AblePlayer.prototype.showMeta = function(now) {
7232-
var m, thisMeta, cues;
7248+
var m, thisMeta, cues, cueText, cueLines, i, line;
72337249
if (this.meta.length >= 1) {
72347250
cues = this.meta;
72357251
}
@@ -7242,15 +7258,45 @@
72427258
break;
72437259
}
72447260
}
7245-
if (typeof thisMeta !== 'undefined') {
7246-
if (this.currentMeta !== thisMeta) {
7247-
// it's time to load the new metadata cue into the container div
7248-
this.$metaDiv.html(this.flattenCueForMeta(cues[thisMeta]).replace('\n', '<br>'));
7261+
if (typeof thisMeta !== 'undefined') {
7262+
if (this.currentMeta !== thisMeta) {
7263+
if (this.metaType === 'text') {
7264+
// it's time to load the new metadata cue into the container div
7265+
this.$metaDiv.html(this.flattenCueForMeta(cues[thisMeta]).replace('\n', '<br>'));
7266+
}
7267+
else if (this.metaType === 'selector') {
7268+
// it's time to show content referenced by the designated selector(s)
7269+
cueText = this.flattenCueForMeta(cues[thisMeta]);
7270+
cueLines = cueText.split('\n');
7271+
for (i=0; i<cueLines.length; i++) {
7272+
line = $.trim(cueLines[i]);
7273+
if (line.toLowerCase() === 'pause') {
7274+
this.pauseMedia();
7275+
}
7276+
else {
7277+
if ($(line).length) {
7278+
// selector exists
7279+
$(line).show();
7280+
// add to array of visible selectors so it can be hidden at end time
7281+
this.visibleSelectors.push(line);
7282+
}
7283+
}
7284+
}
7285+
}
72497286
this.currentMeta = thisMeta;
72507287
}
72517288
}
7252-
else {
7253-
this.$metaDiv.html('');
7289+
else {
7290+
if (typeof this.$metaDiv !== 'undefined') {
7291+
this.$metaDiv.html('');
7292+
}
7293+
if (this.visibleSelectors.length) {
7294+
for (i=0; i<this.visibleSelectors.length; i++) {
7295+
$(this.visibleSelectors[i]).hide();
7296+
}
7297+
// reset array
7298+
this.visibleSelectors = [];
7299+
}
72547300
this.currentMeta = -1;
72557301
}
72567302
};

0 commit comments

Comments
 (0)