@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
102 lines (99 loc) • 3.33 kB
JavaScript
var R = Object.defineProperty;
var b = (r) => {
throw TypeError(r);
};
var S = (r, e, t) => e in r ? R(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var m = (r, e, t) => S(r, typeof e != "symbol" ? e + "" : e, t), $ = (r, e, t) => e.has(r) || b("Cannot " + t);
var f = (r, e, t) => e.has(r) ? b("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
var h = (r, e, t) => ($(r, e, "access private method"), t);
var p = (r, e, t) => new Promise((i, l) => {
var a = (s) => {
try {
n(t.next(s));
} catch (T) {
l(T);
}
}, c = (s) => {
try {
n(t.throw(s));
} catch (T) {
l(T);
}
}, n = (s) => s.done ? i(s.value) : Promise.resolve(s.value).then(a, c);
n((t = t.apply(r, e)).next());
});
import P from "./Base.js";
import { P as d, S as g } from "../PlayerError-JebC7rsX.js";
/*!
* SlashedCloud v0.1.2 (https://github.com/SlashedCloud/player#readme)
* Copyright 2024-2024 rogerio.jardim@fedrax.pt
* Licensed under Apache (https://github.com/SlashedCloud/player/blob/develop/LICENSE)
*/
var o, y, x, u, w;
class M extends P {
constructor(t, i) {
super(t);
f(this, o);
m(this, "name", "SubtitlesPlugin");
m(this, "options");
m(this, "fallbackLocale", "en");
this.options = i;
}
setup() {
return p(this, null, function* () {
const t = [];
for (const i of this.options) {
const { src: l, lang: a } = h(this, o, y).call(this, i);
if (t.includes(a)) continue;
t.push(a);
const c = yield this.player.basePlayer.addTextTrackAsync(l, a, "subtitles", "text/vtt");
a === this.player.language && (this.player.basePlayer.selectTextTrack(c), yield this.player.basePlayer.setTextTrackVisibility(!0));
}
});
}
}
o = new WeakSet(), y = function(t) {
var l;
const i = (l = t.lang) != null ? l : this.player.language;
if (t.subtitles) {
t.subtitles.sort((n, s) => n.startTime - s.startTime);
for (const n in t.subtitles) {
const s = t.subtitles[n];
if (s.endTime && s.startTime > s.endTime && s.startTime < 0)
throw new d(this.name, g.ERROR, `StartTime is bigger than endTime in ${n}`);
}
const a = h(this, o, x).call(this, t.subtitles);
return { src: h(this, o, w).call(this, a), lang: i };
} else {
if (t.src)
return { src: t.src, lang: i };
throw new d(this.name, g.ERROR, "Source is not provided");
}
}, x = function(t) {
let i = `WEBVTT
`;
for (const l in t) {
const a = t[l], c = h(this, o, u).call(this, a.startTime);
let n;
if (a.endTime)
n = h(this, o, u).call(this, a.endTime);
else {
const s = t[parseInt(l) + 1];
n = s ? h(this, o, u).call(this, s.startTime) : h(this, o, u).call(this, this.player.videoElement.duration);
}
i += `${parseInt(l, 10) + 1}
${c} --> ${n}
${a.title}
`;
}
return i;
}, u = function(t) {
const i = (s, T) => s.toString().padStart(T, "0"), l = i(Math.floor(t / 3600), 2), a = i(Math.floor(t % 3600 / 60), 2), c = i(Math.floor(t % 60), 2), n = i(Math.floor((t - Math.floor(t)) * 1e3), 3);
return `${l}:${a}:${c}.${n}`;
}, w = function(t) {
const i = new Blob([t], { type: "text/vtt" });
return URL.createObjectURL(i);
};
export {
M as default
};