123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
-
- var _slider = require("antd/es/slider");
-
- var _slider2 = _interopRequireDefault(_slider);
-
- var _icon = require("antd/es/icon");
-
- var _icon2 = _interopRequireDefault(_icon);
-
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
-
- require("antd/es/slider/style");
-
- require("antd/es/icon/style");
-
- var _react = require("react");
-
- var _react2 = _interopRequireDefault(_react);
-
- var _dayjs = require("dayjs");
-
- var _dayjs2 = _interopRequireDefault(_dayjs);
-
- var _duration = require("dayjs/plugin/duration");
-
- var _duration2 = _interopRequireDefault(_duration);
-
- var _utc = require("dayjs/plugin/utc");
-
- var _utc2 = _interopRequireDefault(_utc);
-
- require("./index.less");
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
-
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
-
- _dayjs2.default.extend(_duration2.default);
- _dayjs2.default.extend(_utc2.default);
-
- var AudioPlayer = function (_React$Component) {
- _inherits(AudioPlayer, _React$Component);
-
- function AudioPlayer(props) {
- _classCallCheck(this, AudioPlayer);
-
- var _this = _possibleConstructorReturn(this, (AudioPlayer.__proto__ || Object.getPrototypeOf(AudioPlayer)).call(this, props));
-
- _this.state = {
- duration: 0,
- currentDuration: 0,
- isPlaying: false
- };
- return _this;
- }
-
- _createClass(AudioPlayer, [{
- key: "componentDidMount",
- value: function componentDidMount() {
- var _this2 = this;
-
- if (this.player) {
- var src = this.props.src;
-
- this.player.oncanplay = function (event) {
- return _this2.setState({ duration: event.target.duration });
- };
- this.player.onended = function () {
- return _this2.setState({ isPlaying: false, currentDuration: 0 });
- };
- this.player.onpause = function () {
- return _this2.setState({ isPlaying: false });
- };
- this.player.onplay = function () {
- return _this2.setState({ isPlaying: true });
- };
- this.player.ontimeupdate = function (event) {
- return _this2.setState({ currentDuration: event.target.currentTime });
- };
- this.player.src = src;
- }
- }
- }, {
- key: "componentDidUpdate",
- value: function componentDidUpdate(prevProps) {
- var _this3 = this;
-
- if (this.props.src !== prevProps.src) {
- this.player.oncanplay = function (event) {
- return _this3.setState({ duration: event.target.duration });
- };
- this.player.onended = function () {
- return _this3.setState({ isPlaying: false, currentDuration: 0 });
- };
- this.player.onpause = function () {
- return _this3.setState({ isPlaying: false });
- };
- this.player.onplay = function () {
- return _this3.setState({ isPlaying: true });
- };
- this.player.ontimeupdate = function (event) {
- return _this3.setState({ currentDuration: event.target.currentTime });
- };
- this.player.src = this.props.src;
- }
- }
- }, {
- key: "clickPlayOrPause",
- value: function clickPlayOrPause(isPlaying) {
- if (!this.player) {
- return;
- }
- if (isPlaying) {
- this.player.pause();
- } else {
- // 如果是播放,先暂停其他的播放
- var playerList = document.getElementsByTagName("audio");
- if (playerList) {
- Array.from(playerList).forEach(function (player) {
- if (!player.paused) {
- player.pause();
- }
- });
- }
- this.player.play();
- }
- }
- }, {
- key: "render",
- value: function render() {
- var _this4 = this;
-
- var _state = this.state,
- currentDuration = _state.currentDuration,
- isPlaying = _state.isPlaying,
- duration = _state.duration;
-
- return _react2.default.createElement(
- "div",
- { className: "comment-item-speak-audio-container" },
- _react2.default.createElement("audio", {
- ref: function ref(_ref) {
- _this4.player = _ref;
- },
- style: { display: "none" }
- }),
- _react2.default.createElement(
- "span",
- {
- className: "icon",
- onClick: function onClick() {
- _this4.clickPlayOrPause(isPlaying);
- }
- },
- isPlaying ? _react2.default.createElement(_icon2.default, { className: "pause", type: "pause" }) : _react2.default.createElement("i", { className: "schedule schedule-icon_image_audio" })
- ),
- _react2.default.createElement(_slider2.default, {
- step: 0.001,
- className: "slider",
- tooltipVisible: false,
- value: currentDuration,
- max: duration,
- onChange: function onChange(value) {
- if (_this4.player) {
- _this4.player.currentTime = value;
- }
- }
- }),
- _react2.default.createElement(
- "span",
- { className: "time" },
- _dayjs2.default.utc(_dayjs2.default.duration(currentDuration, "seconds").asMilliseconds()).format("mm:ss"),
- "/",
- _dayjs2.default.utc(_dayjs2.default.duration(duration, "seconds").asMilliseconds()).format("mm:ss")
- )
- );
- }
- }]);
-
- return AudioPlayer;
- }(_react2.default.Component);
-
- exports.default = AudioPlayer;
- //# sourceMappingURL=index.js.map
|