UNPKG

material-ui-audio-player

Version:
149 lines 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PLAYER_LOOP = exports.PLAYER_AUTOPLAY = exports.PLAYER_REPLAY = exports.PLAYER_AUDIO_ENDED = exports.PLAYER_SLIDER_MOVED = exports.PLAYER_SET_TIME = exports.PLAYER_SET_DURATION = exports.PLAYER_VOLUME_CHANGE = exports.PLAYER_STATUS_PAUSE = exports.PLAYER_STATUS_PLAY = exports.PLAYER_VOLUME_STATUS_MUTE = exports.PLAYER_VOLUME_STATUS_UNMUTE = exports.actionCreators = void 0; var helpers_1 = require("./helpers"); var PLAYER_STATUS_PLAY = 'PLAYER_STATUS_PLAY'; exports.PLAYER_STATUS_PLAY = PLAYER_STATUS_PLAY; var PLAYER_STATUS_PAUSE = 'PLAYER_STATUS_PAUSE'; exports.PLAYER_STATUS_PAUSE = PLAYER_STATUS_PAUSE; var PLAYER_VOLUME_STATUS_UNMUTE = 'PLAYER_VOLUME_STATUS_UNMUTE'; exports.PLAYER_VOLUME_STATUS_UNMUTE = PLAYER_VOLUME_STATUS_UNMUTE; var PLAYER_VOLUME_STATUS_MUTE = 'PLAYER_VOLUME_STATUS_MUTE'; exports.PLAYER_VOLUME_STATUS_MUTE = PLAYER_VOLUME_STATUS_MUTE; var PLAYER_VOLUME_CHANGE = 'PLAYER_VOLUME_CHANGE'; exports.PLAYER_VOLUME_CHANGE = PLAYER_VOLUME_CHANGE; var PLAYER_SET_DURATION = 'PLAYER_SET_DURATION'; exports.PLAYER_SET_DURATION = PLAYER_SET_DURATION; var PLAYER_SET_TIME = 'PLAYER_SET_TIME'; exports.PLAYER_SET_TIME = PLAYER_SET_TIME; var PLAYER_SLIDER_MOVED = 'PLAYER_SLIDER_MOVED'; exports.PLAYER_SLIDER_MOVED = PLAYER_SLIDER_MOVED; var PLAYER_AUDIO_ENDED = 'PLAYER_AUDIO_ENDED'; exports.PLAYER_AUDIO_ENDED = PLAYER_AUDIO_ENDED; var PLAYER_REPLAY = 'PLAYER_REPLAY'; exports.PLAYER_REPLAY = PLAYER_REPLAY; var PLAYER_AUTOPLAY = 'PLAYER_AUTOPLAY'; exports.PLAYER_AUTOPLAY = PLAYER_AUTOPLAY; var PLAYER_LOOP = 'PLAYER_LOOP'; exports.PLAYER_LOOP = PLAYER_LOOP; function playAudio(dispatch, player) { return function () { if (player.current) { player.current.play(); } return dispatch({ type: PLAYER_STATUS_PLAY }); }; } function pauseAudio(dispatch, player) { return function () { if (player.current) { player.current.pause(); } dispatch({ type: PLAYER_STATUS_PAUSE }); }; } function muteAudio(dispatch, player) { return function () { if (player.current) { player.current.muted = true; } dispatch({ type: PLAYER_VOLUME_STATUS_MUTE }); }; } function unmuteAudio(dispatch, player) { return function () { if (player.current) { player.current.muted = false; } dispatch({ type: PLAYER_VOLUME_STATUS_UNMUTE }); }; } function changeAudioVolume(dispatch, player) { return function (value) { if (player.current) { player.current.volume = value > 0 ? value / 100 : 0; if (player.current.muted) { player.current.muted = false; } } dispatch({ type: PLAYER_VOLUME_CHANGE, volumeValue: value }); }; } function setPlayerDuration(dispatch, player) { return function () { dispatch({ type: PLAYER_SET_DURATION, duration: player.current.duration }); }; } function setPlayerTime(dispatch, player) { return function () { var _a, _b, _c, _d; var progress = helpers_1.getProgress((_a = player === null || player === void 0 ? void 0 : player.current) === null || _a === void 0 ? void 0 : _a.currentTime, (_b = player === null || player === void 0 ? void 0 : player.current) === null || _b === void 0 ? void 0 : _b.duration); var remaning = helpers_1.getRemaningTime(progress, (_c = player === null || player === void 0 ? void 0 : player.current) === null || _c === void 0 ? void 0 : _c.duration); dispatch({ type: PLAYER_SET_TIME, current: (_d = player === null || player === void 0 ? void 0 : player.current) === null || _d === void 0 ? void 0 : _d.currentTime, remaning: remaning, progress: progress, }); }; } function changePlayerSlider(dispatch, player) { return function (progress) { var currentTime = helpers_1.getCurrentTime(progress, player.current.duration); var remaningTime = helpers_1.getRemaningTime(progress, player.current.duration); if (currentTime) { player.current.currentTime = currentTime; } dispatch({ type: PLAYER_SLIDER_MOVED, progress: progress, current: currentTime, remaning: remaningTime, }); }; } function audioEnded(dispatch) { return function () { dispatch({ type: PLAYER_AUDIO_ENDED }); }; } function replayAudio(dispatch, player) { return function () { if (player.current) { player.current.play(); } dispatch({ type: PLAYER_REPLAY }); }; } function loopAudio(dispatch, player) { return function (loop) { if (player.current) { player.current.loop = loop; } dispatch({ type: PLAYER_LOOP, loop: loop }); }; } function setPlayerAutoplay(dispatch, player) { return function () { if (player.current) { player.current.autoplay = true; } dispatch({ type: PLAYER_AUTOPLAY }); }; } var actionCreators = [ playAudio, pauseAudio, muteAudio, unmuteAudio, changeAudioVolume, setPlayerDuration, setPlayerTime, audioEnded, replayAudio, changePlayerSlider, setPlayerAutoplay, loopAudio, ]; exports.actionCreators = actionCreators; //# sourceMappingURL=actions.js.map