UNPKG

@metacell/geppetto-meta-ui

Version:

React components from geppetto-meta to create neuroscience applications and visualize data.

165 lines 6.84 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } import React, { Component } from 'react'; import { PropTypes } from 'prop-types'; import ReactPlayer from 'react-player'; var MoviePlayer = /*#__PURE__*/function (_Component) { function MoviePlayer(props) { var _this; _classCallCheck(this, MoviePlayer); _this = _callSuper(this, MoviePlayer, [props]); _this.state = { play: false, volume: 1, // can be any value from 0 to 1 videoURL: "", // URL pointing to the file to be played loop: false, // play video again at end of video playbackRate: 1 // playback rate any decimal }; return _this; } _inherits(MoviePlayer, _Component); return _createClass(MoviePlayer, [{ key: "play", value: function play() { this.setState({ play: true }); this.forceUpdate(); } }, { key: "pause", value: function pause() { this.setState({ play: false }); this.forceUpdate(); } }, { key: "loop", value: function loop(_loop) { this.setState({ loop: _loop }); this.forceUpdate(); } }, { key: "stop", value: function stop() { this.setState({ play: false }); this.forceUpdate(); } }, { key: "load", value: function load(url) { this.setState({ videoURL: url }); this.forceUpdate(); } }, { key: "componentDidMount", value: function componentDidMount() { if (this.props.controls != null || this.props.controls != undefined) { var play = this.props.controls.playAtStart != undefined ? this.props.controls.playAtStart : this.state.play; var loop = this.props.controls.loop != undefined ? this.props.controls.loop : this.state.loop; var volume = this.props.controls.volume != undefined ? this.props.controls.volume : this.state.volume; var playbackRate = this.props.controls.playbackRate != undefined ? this.props.controls.playbackRate : this.state.playbackRate; this.setState({ play: play, loop: loop, volume: volume, playbackRate: playbackRate, videoURL: this.props.videoURL }); } else { this.setState({ videoURL: this.props.videoURL }); } this.forceUpdate(); } }, { key: "render", value: function render() { var width = "100%", height = "100%"; if (this.props.width != undefined && this.props.width != null) { width = this.props.width; } if (this.props.height != undefined && this.props.height != null) { height = this.props.height; } return /*#__PURE__*/React.createElement(ReactPlayer, { url: this.state.videoURL, playing: this.state.play, volume: this.state.volume, loop: this.state.loop, playbackRate: this.state.playbackRate, width: width, height: height }); } }]); }(Component); export { MoviePlayer as default }; MoviePlayer.defaultValues = { controls: { playAtStart: false, loop: false, volume: 10, playbackRate: 1 }, width: '800px', height: '640px' }; MoviePlayer.propTypes = { /** * URL pointing to the video to be rendered in this component. */ videoURL: PropTypes.string.isRequired, /** * Javascript object with playback settings. */ controls: PropTypes.shape({ /** * Boolean value indicating if video should play at the start. Defaults to false. */ playAtStart: PropTypes.bool, /** * Boolean value indicating if the video should be played in a loop. Defaults to false. */ loop: PropTypes.bool, /** * Start volume of the video. */ volume: PropTypes.number, /** * Playback rate of the video. */ playbackRate: PropTypes.number }), /** * Width of the movie player */ width: PropTypes.string, /** * Height of the movie player */ height: PropTypes.string };