react-player
Version:
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
101 lines (100 loc) • 2.86 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
import React, { Component } from "react";
import { callPlayer, getSDK, queryString } from "../utils.js";
import { canPlay, MATCH_URL_MIXCLOUD } from "../patterns.js";
const SDK_URL = "https://widget.mixcloud.com/media/js/widgetApi.js";
const SDK_GLOBAL = "Mixcloud";
class Mixcloud extends Component {
constructor() {
super(...arguments);
__publicField(this, "callPlayer", callPlayer);
__publicField(this, "duration", null);
__publicField(this, "currentTime", null);
__publicField(this, "secondsLoaded", null);
__publicField(this, "mute", () => {
});
__publicField(this, "unmute", () => {
});
__publicField(this, "ref", (iframe) => {
this.iframe = iframe;
});
}
componentDidMount() {
this.props.onMount && this.props.onMount(this);
}
load(url) {
getSDK(SDK_URL, SDK_GLOBAL).then((Mixcloud2) => {
this.player = Mixcloud2.PlayerWidget(this.iframe);
this.player.ready.then(() => {
this.player.events.play.on(this.props.onPlay);
this.player.events.pause.on(this.props.onPause);
this.player.events.ended.on(this.props.onEnded);
this.player.events.error.on(this.props.error);
this.player.events.progress.on((seconds, duration) => {
this.currentTime = seconds;
this.duration = duration;
});
this.props.onReady();
});
}, this.props.onError);
}
play() {
this.callPlayer("play");
}
pause() {
this.callPlayer("pause");
}
stop() {
}
seekTo(seconds, keepPlaying = true) {
this.callPlayer("seek", seconds);
if (!keepPlaying) {
this.pause();
}
}
setVolume(fraction) {
}
getDuration() {
return this.duration;
}
getCurrentTime() {
return this.currentTime;
}
getSecondsLoaded() {
return null;
}
render() {
const { url, config } = this.props;
const id = url.match(MATCH_URL_MIXCLOUD)[1];
const style = {
width: "100%",
height: "100%"
};
const query = queryString({
...config.options,
feed: `/${id}/`
});
return /* @__PURE__ */ React.createElement(
"iframe",
{
key: id,
ref: this.ref,
style,
src: `https://www.mixcloud.com/widget/iframe/?${query}`,
frameBorder: "0",
allow: "autoplay"
}
);
}
}
__publicField(Mixcloud, "displayName", "Mixcloud");
__publicField(Mixcloud, "canPlay", canPlay.mixcloud);
__publicField(Mixcloud, "loopOnEnded", true);
export {
Mixcloud as default
};