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,5 +1,5 @@
import { store } from '~/redux/store';
import { playerSetStatus } from '~/redux/player/actions';
import { playerSetStatus, playerStopped } from '~/redux/player/actions';
import { PLAYER_STATES } from '~/redux/player/constants';
type PlayerEventType = keyof HTMLMediaElementEventMap;
@ -64,6 +64,11 @@ export class PlayerClass {
this.element.pause();
};
public stop = () => {
this.element.src = '';
this.element.dispatchEvent(new CustomEvent('stop'));
};
public getDuration = () => {
return this.element.currentTime;
};
@ -83,5 +88,7 @@ const Player = new PlayerClass();
Player.on('play', () => store.dispatch(playerSetStatus(PLAYER_STATES.PLAYING)));
Player.on('pause', () => store.dispatch(playerSetStatus(PLAYER_STATES.PAUSED)));
Player.on('stop', () => store.dispatch(playerStopped()));
Player.on('error', () => store.dispatch(playerStopped()));
export { Player };