1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

better audio player

This commit is contained in:
Fedor Katurov 2019-10-15 17:30:31 +07:00
parent 87b9b5f514
commit c84dfdd2ab
7 changed files with 54 additions and 14 deletions

View file

@ -1,10 +1,11 @@
import { takeLatest } from 'redux-saga/effects';
import { PLAYER_ACTIONS } from './constants';
import { playerSetFile, playerSeek } from './actions';
import { takeLatest, put } from 'redux-saga/effects';
import { PLAYER_ACTIONS, PLAYER_STATES } from './constants';
import { playerSetFile, playerSeek, playerSetStatus } from './actions';
import { Player } from '~/utils/player';
import { getURL } from '~/utils/dom';
function setFileSaga({ file }: ReturnType<typeof playerSetFile>) {
function* setFileAndPlaySaga({ file }: ReturnType<typeof playerSetFile>) {
yield put(playerSetFile(file));
Player.set(getURL(file));
Player.play();
}
@ -17,13 +18,24 @@ function pauseSaga() {
Player.pause();
}
function stopSaga() {
Player.stop();
}
function seekSaga({ seek }: ReturnType<typeof playerSeek>) {
Player.jumpToPercent(seek * 100);
}
function* stoppedSaga() {
yield put(playerSetStatus(PLAYER_STATES.UNSET));
yield put(playerSetFile(null));
}
export default function* playerSaga() {
yield takeLatest(PLAYER_ACTIONS.SET_FILE, setFileSaga);
yield takeLatest(PLAYER_ACTIONS.SET_FILE_AND_PLAY, setFileAndPlaySaga);
yield takeLatest(PLAYER_ACTIONS.PAUSE, pauseSaga);
yield takeLatest(PLAYER_ACTIONS.PLAY, playSaga);
yield takeLatest(PLAYER_ACTIONS.SEEK, seekSaga);
yield takeLatest(PLAYER_ACTIONS.STOP, stopSaga);
yield takeLatest(PLAYER_ACTIONS.STOPPED, stoppedSaga);
}