react-tv-player
Version:
A React media player component for TV devices. With custom UI and arrow-key navigation, it can play a variety of URLs like file paths, HLS/DASH streams and even YouTube & Vimeo links directly. Packaged as an npm library for easy integration.
126 lines (125 loc) • 4.37 kB
JavaScript
import { r as D, a as M, g as S } from "./index-r8XrYpcu.js";
import T from "react";
function E(l, o) {
for (var u = 0; u < o.length; u++) {
const s = o[u];
if (typeof s != "string" && !Array.isArray(s)) {
for (const n in s)
if (n !== "default" && !(n in l)) {
const p = Object.getOwnPropertyDescriptor(s, n);
p && Object.defineProperty(l, n, p.get ? p : {
enumerable: !0,
get: () => s[n]
});
}
}
}
return Object.freeze(Object.defineProperty(l, Symbol.toStringTag, { value: "Module" }));
}
var h, P;
function x() {
if (P) return h;
P = 1;
var l = Object.create, o = Object.defineProperty, u = Object.getOwnPropertyDescriptor, s = Object.getOwnPropertyNames, n = Object.getPrototypeOf, p = Object.prototype.hasOwnProperty, v = (t, e, r) => e in t ? o(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, b = (t, e) => {
for (var r in e)
o(t, r, { get: e[r], enumerable: !0 });
}, f = (t, e, r, c) => {
if (e && typeof e == "object" || typeof e == "function")
for (let i of s(e))
!p.call(t, i) && i !== r && o(t, i, { get: () => e[i], enumerable: !(c = u(e, i)) || c.enumerable });
return t;
}, O = (t, e, r) => (r = t != null ? l(n(t)) : {}, f(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
!t || !t.__esModule ? o(r, "default", { value: t, enumerable: !0 }) : r,
t
)), w = (t) => f(o({}, "__esModule", { value: !0 }), t), a = (t, e, r) => (v(t, typeof e != "symbol" ? e + "" : e, r), r), y = {};
b(y, {
default: () => d
}), h = w(y);
var _ = O(T), m = /* @__PURE__ */ D(), K = /* @__PURE__ */ M();
const j = "https://cdn.embed.ly/player-0.1.0.min.js", L = "playerjs";
class d extends _.Component {
constructor() {
super(...arguments), a(this, "callPlayer", m.callPlayer), a(this, "duration", null), a(this, "currentTime", null), a(this, "secondsLoaded", null), a(this, "mute", () => {
this.callPlayer("mute");
}), a(this, "unmute", () => {
this.callPlayer("unmute");
}), a(this, "ref", (e) => {
this.iframe = e;
});
}
componentDidMount() {
this.props.onMount && this.props.onMount(this);
}
load(e) {
(0, m.getSDK)(j, L).then((r) => {
this.iframe && (this.player = new r.Player(this.iframe), this.player.on("ready", () => {
setTimeout(() => {
this.player.isReady = !0, this.player.setLoop(this.props.loop), this.props.muted && this.player.mute(), this.addListeners(this.player, this.props), this.props.onReady();
}, 500);
}));
}, this.props.onError);
}
addListeners(e, r) {
e.on("play", r.onPlay), e.on("pause", r.onPause), e.on("ended", r.onEnded), e.on("error", r.onError), e.on("timeupdate", ({ duration: c, seconds: i }) => {
this.duration = c, this.currentTime = i;
});
}
play() {
this.callPlayer("play");
}
pause() {
this.callPlayer("pause");
}
stop() {
}
seekTo(e, r = !0) {
this.callPlayer("setCurrentTime", e), r || this.pause();
}
setVolume(e) {
this.callPlayer("setVolume", e);
}
setLoop(e) {
this.callPlayer("setLoop", e);
}
getDuration() {
return this.duration;
}
getCurrentTime() {
return this.currentTime;
}
getSecondsLoaded() {
return this.secondsLoaded;
}
render() {
const e = {
width: "100%",
height: "100%"
};
return /* @__PURE__ */ _.default.createElement(
"iframe",
{
ref: this.ref,
src: this.props.url,
frameBorder: "0",
scrolling: "no",
style: e,
allow: "encrypted-media; autoplay; fullscreen;",
referrerPolicy: "no-referrer-when-downgrade"
}
);
}
}
return a(d, "displayName", "Kaltura"), a(d, "canPlay", K.canPlay.kaltura), h;
}
var g = /* @__PURE__ */ x();
const N = /* @__PURE__ */ S(g), R = /* @__PURE__ */ E({
__proto__: null,
default: N
}, [g]);
export {
R as K
};