UNPKG

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.

127 lines (126 loc) 4.59 kB
import { r as T, a as N, g as x } from "./index-r8XrYpcu.js"; import A from "react"; function q(l, s) { for (var p = 0; p < s.length; p++) { const i = s[p]; if (typeof i != "string" && !Array.isArray(i)) { for (const n in i) if (n !== "default" && !(n in l)) { const d = Object.getOwnPropertyDescriptor(i, n); d && Object.defineProperty(l, n, d.get ? d : { enumerable: !0, get: () => i[n] }); } } } return Object.freeze(Object.defineProperty(l, Symbol.toStringTag, { value: "Module" })); } var f, g; function U() { if (g) return f; g = 1; var l = Object.create, s = Object.defineProperty, p = Object.getOwnPropertyDescriptor, i = Object.getOwnPropertyNames, n = Object.getPrototypeOf, d = Object.prototype.hasOwnProperty, v = (t, e, r) => e in t ? s(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, O = (t, e) => { for (var r in e) s(t, r, { get: e[r], enumerable: !0 }); }, y = (t, e, r, c) => { if (e && typeof e == "object" || typeof e == "function") for (let a of i(e)) !d.call(t, a) && a !== r && s(t, a, { get: () => e[a], enumerable: !(c = p(e, a)) || c.enumerable }); return t; }, S = (t, e, r) => (r = t != null ? l(n(t)) : {}, y( // 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 ? s(r, "default", { value: t, enumerable: !0 }) : r, t )), C = (t) => y(s({}, "__esModule", { value: !0 }), t), o = (t, e, r) => (v(t, typeof e != "symbol" ? e + "" : e, r), r), _ = {}; O(_, { default: () => h }), f = C(_); var m = S(A), P = /* @__PURE__ */ T(), w = /* @__PURE__ */ N(); const j = "https://w.soundcloud.com/player/api.js", E = "SC"; class h extends m.Component { constructor() { super(...arguments), o(this, "callPlayer", P.callPlayer), o(this, "duration", null), o(this, "currentTime", null), o(this, "fractionLoaded", null), o(this, "mute", () => { this.setVolume(0); }), o(this, "unmute", () => { this.props.volume !== null && this.setVolume(this.props.volume); }), o(this, "ref", (e) => { this.iframe = e; }); } componentDidMount() { this.props.onMount && this.props.onMount(this); } load(e, r) { (0, P.getSDK)(j, E).then((c) => { if (!this.iframe) return; const { PLAY: a, PLAY_PROGRESS: D, PAUSE: L, FINISH: R, ERROR: M } = c.Widget.Events; r || (this.player = c.Widget(this.iframe), this.player.bind(a, this.props.onPlay), this.player.bind(L, () => { this.duration - this.currentTime < 0.05 || this.props.onPause(); }), this.player.bind(D, (u) => { this.currentTime = u.currentPosition / 1e3, this.fractionLoaded = u.loadedProgress; }), this.player.bind(R, () => this.props.onEnded()), this.player.bind(M, (u) => this.props.onError(u))), this.player.load(e, { ...this.props.config.options, callback: () => { this.player.getDuration((u) => { this.duration = u / 1e3, this.props.onReady(); }); } }); }); } play() { this.callPlayer("play"); } pause() { this.callPlayer("pause"); } stop() { } seekTo(e, r = !0) { this.callPlayer("seekTo", e * 1e3), r || this.pause(); } setVolume(e) { this.callPlayer("setVolume", e * 100); } getDuration() { return this.duration; } getCurrentTime() { return this.currentTime; } getSecondsLoaded() { return this.fractionLoaded * this.duration; } render() { const { display: e } = this.props, r = { width: "100%", height: "100%", display: e }; return /* @__PURE__ */ m.default.createElement( "iframe", { ref: this.ref, src: `https://w.soundcloud.com/player/?url=${encodeURIComponent(this.props.url)}`, style: r, frameBorder: 0, allow: "autoplay" } ); } } return o(h, "displayName", "SoundCloud"), o(h, "canPlay", w.canPlay.soundcloud), o(h, "loopOnEnded", !0), f; } var b = /* @__PURE__ */ U(); const V = /* @__PURE__ */ x(b), I = /* @__PURE__ */ q({ __proto__: null, default: V }, [b]); export { I as S };