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.
118 lines (117 loc) • 4.4 kB
JavaScript
import { r as x, a as C, g as N } from "./index-r8XrYpcu.js";
import q from "react";
function T(l, a) {
for (var p = 0; p < a.length; p++) {
const o = a[p];
if (typeof o != "string" && !Array.isArray(o)) {
for (const s in o)
if (s !== "default" && !(s in l)) {
const u = Object.getOwnPropertyDescriptor(o, s);
u && Object.defineProperty(l, s, u.get ? u : {
enumerable: !0,
get: () => o[s]
});
}
}
}
return Object.freeze(Object.defineProperty(l, Symbol.toStringTag, { value: "Module" }));
}
var P, O;
function k() {
if (O) return P;
O = 1;
var l = Object.create, a = Object.defineProperty, p = Object.getOwnPropertyDescriptor, o = Object.getOwnPropertyNames, s = Object.getPrototypeOf, u = Object.prototype.hasOwnProperty, D = (t, e, r) => e in t ? a(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, j = (t, e) => {
for (var r in e)
a(t, r, { get: e[r], enumerable: !0 });
}, m = (t, e, r, d) => {
if (e && typeof e == "object" || typeof e == "function")
for (let i of o(e))
!u.call(t, i) && i !== r && a(t, i, { get: () => e[i], enumerable: !(d = p(e, i)) || d.enumerable });
return t;
}, w = (t, e, r) => (r = t != null ? l(s(t)) : {}, m(
// 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 ? a(r, "default", { value: t, enumerable: !0 }) : r,
t
)), S = (t) => m(a({}, "__esModule", { value: !0 }), t), n = (t, e, r) => (D(t, typeof e != "symbol" ? e + "" : e, r), r), v = {};
j(v, {
default: () => c
}), P = S(v);
var y = w(q), g = /* @__PURE__ */ x(), b = /* @__PURE__ */ C();
const M = "https://play.vidyard.com/embed/v4.js", A = "VidyardV4", E = "onVidyardAPI";
class c extends y.Component {
constructor() {
super(...arguments), n(this, "callPlayer", g.callPlayer), n(this, "mute", () => {
this.setVolume(0);
}), n(this, "unmute", () => {
this.props.volume !== null && this.setVolume(this.props.volume);
}), n(this, "ref", (e) => {
this.container = e;
});
}
componentDidMount() {
this.props.onMount && this.props.onMount(this);
}
load(e) {
const { playing: r, config: d, onError: i, onDuration: L } = this.props, h = e && e.match(b.MATCH_URL_VIDYARD)[1];
this.player && this.stop(), (0, g.getSDK)(M, A, E).then((_) => {
this.container && (_.api.addReadyListener((f, R) => {
this.player || (this.player = R, this.player.on("ready", this.props.onReady), this.player.on("play", this.props.onPlay), this.player.on("pause", this.props.onPause), this.player.on("seek", this.props.onSeek), this.player.on("playerComplete", this.props.onEnded));
}, h), _.api.renderPlayer({
uuid: h,
container: this.container,
autoplay: r ? 1 : 0,
...d.options
}), _.api.getPlayerMetadata(h).then((f) => {
this.duration = f.length_in_seconds, L(f.length_in_seconds);
}));
}, i);
}
play() {
this.callPlayer("play");
}
pause() {
this.callPlayer("pause");
}
stop() {
window.VidyardV4.api.destroyPlayer(this.player);
}
seekTo(e, r = !0) {
this.callPlayer("seek", e), r || this.pause();
}
setVolume(e) {
this.callPlayer("setVolume", e);
}
setPlaybackRate(e) {
this.callPlayer("setPlaybackSpeed", e);
}
getDuration() {
return this.duration;
}
getCurrentTime() {
return this.callPlayer("currentTime");
}
getSecondsLoaded() {
return null;
}
render() {
const { display: e } = this.props, r = {
width: "100%",
height: "100%",
display: e
};
return /* @__PURE__ */ y.default.createElement("div", { style: r }, /* @__PURE__ */ y.default.createElement("div", { ref: this.ref }));
}
}
return n(c, "displayName", "Vidyard"), n(c, "canPlay", b.canPlay.vidyard), P;
}
var V = /* @__PURE__ */ k();
const K = /* @__PURE__ */ N(V), B = /* @__PURE__ */ T({
__proto__: null,
default: K
}, [V]);
export {
B as V
};