This repository has been archived on 2024-08-27. You can view files and clone it, but cannot push or open issues or pull requests.
negromate_origins/web/negromateweb/static/js/videojs-ass/src/videojs.ass.js

123 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-10-12 23:00:20 +02:00
/*! videojs-ass
* Copyright (c) 2014 Sunny Li
* Licensed under the Apache-2.0 license. */
(function (videojs, libjass) {
'use strict';
var vjs_ass = function (options) {
var overlay = document.createElement('div'),
clock = null,
2018-10-12 23:00:20 +02:00
clockRate = options.rate || 1,
delay = options.delay || 0,
player = this,
renderer = null,
AssButton = null,
AssButtonInstance = null,
VjsButton = null;
2018-10-12 23:00:20 +02:00
if (!options.src) {
return;
}
overlay.className = 'vjs-ass';
player.el().insertBefore(overlay, player.el().firstChild.nextSibling);
2018-10-12 23:00:20 +02:00
function getCurrentTime() {
return player.currentTime() - delay;
}
clock = new libjass.renderers.AutoClock(getCurrentTime, 500);
2018-10-12 23:00:20 +02:00
player.on('play', function () {
clock.play();
2018-10-12 23:00:20 +02:00
});
player.on('pause', function () {
clock.pause();
2018-10-12 23:00:20 +02:00
});
player.on('seeking', function () {
clock.seeking();
2018-10-12 23:00:20 +02:00
});
function updateClockRate() {
clock.setRate(player.playbackRate() * clockRate);
2018-10-12 23:00:20 +02:00
}
2018-10-12 23:00:20 +02:00
updateClockRate();
player.on('ratechange', updateClockRate);
function updateDisplayArea() {
setTimeout(function () {
renderer.resize(player.el().offsetWidth, player.el().offsetHeight);
2018-10-12 23:00:20 +02:00
}, 100);
}
if (player.fluid()) {
window.addEventListener('resize', updateDisplayArea);
}
2018-10-12 23:00:20 +02:00
player.on('loadedmetadata', updateDisplayArea);
player.on('resize', updateDisplayArea);
player.on('fullscreenchange', updateDisplayArea);
player.on('dispose', function () {
clock.disable();
2018-10-12 23:00:20 +02:00
});
libjass.ASS.fromUrl(options.src, libjass.Format.ASS).then(
function (ass) {
var rendererSettings = new libjass.renderers.RendererSettings();
2018-10-12 23:00:20 +02:00
if (options.hasOwnProperty('enableSvg')) {
rendererSettings.enableSvg = options.enableSvg;
}
if (options.hasOwnProperty('fontMap')) {
rendererSettings.fontMap = new libjass.Map(options.fontMap);
} else if (options.hasOwnProperty('fontMapById')) {
rendererSettings.fontMap = libjass.renderers.RendererSettings
.makeFontMapFromStyleElement(document.getElementById(options.fontMapById));
}
renderer = new libjass.renderers.WebRenderer(ass, clock, overlay, rendererSettings);
console.debug(renderer);
2018-10-12 23:00:20 +02:00
}
);
// Visibility Toggle Button
if (!options.hasOwnProperty('button') || options.button) {
VjsButton = videojs.getComponent('Button');
AssButton = videojs.extend(VjsButton, {
constructor: function (player, options) {
options.name = options.name || 'assToggleButton';
VjsButton.call(this, player, options);
this.addClass('vjs-ass-button');
this.on('click', this.onClick);
},
onClick: function () {
if (!this.hasClass('inactive')) {
this.addClass('inactive');
overlay.style.display = "none";
2018-10-12 23:00:20 +02:00
} else {
this.removeClass('inactive');
overlay.style.display = "";
2018-10-12 23:00:20 +02:00
}
}
});
2018-10-12 23:00:20 +02:00
player.ready(function () {
AssButtonInstance = new AssButton(player, options);
player.controlBar.addChild(AssButtonInstance);
player.controlBar.el().insertBefore(
AssButtonInstance.el(),
player.controlBar.getChild('customControlSpacer').el().nextSibling
);
});
}
2018-10-12 23:00:20 +02:00
};
videojs.plugin('ass', vjs_ass);
}(window.videojs, window.libjass));