Skip to content

Instantly share code, notes, and snippets.

@shauns
Last active April 25, 2016 16:51
Show Gist options
  • Save shauns/7358fbff89372ecf7263afad4f46bd67 to your computer and use it in GitHub Desktop.
Save shauns/7358fbff89372ecf7263afad4f46bd67 to your computer and use it in GitHub Desktop.
(function (window, videojs) {
videojs.plugin('pauseOnCue', function() {
var myPlayer = this,
cuePointAra = [],
allCuePointData;
myPlayer.on('loadstart', function () {
cuePointAra = myPlayer.mediainfo.cue_points;
var tt = myPlayer.textTracks()[0];
if (tt) {
tt.oncuechange = function () {
if (tt.activeCues[0] !== undefined) {
var dynamicHTML = "id: " + tt.activeCues[0].id + ", ";
dynamicHTML += "text: " + tt.activeCues[0].text + ", ";
dynamicHTML += "startTime: " + tt.activeCues[0].startTime + ", ";
dynamicHTML += "endTime: " + tt.activeCues[0].endTime;
console.log(dynamicHTML);
allCuePointData = getSubArray(cuePointAra, 'time', tt.activeCues[0].startTime);
console.log('cue point data:', allCuePointData);
console.log('cue point metadata:', allCuePointData[0].metadata);
myPlayer.pause();
}
};
}
});
function getSubArray(targetArray, objProperty, value) {
var i, totalItems = targetArray.length,
objFound = false,
idxArr = [];
for (i = 0; i < totalItems; i++) {
if (targetArray[i][objProperty] === value) {
objFound = true;
idxArr.push(targetArray[i]);
}
}
return idxArr;
}
});
})(window, window.videojs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment