123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import song from "../../../assets/song.mp3"; // delete
- import song2 from "../../../assets/little.mp3"; // delete
- import store from "../../store";
- import types from "../types";
- const audio = new Audio(song);
- export const togglePlay = (status) => {
- status ? audio.play() : audio.pause();
- return { type: types.TOGGLE_PLAY, payload: status };
- };
- export const setDuration = (e) => {
- const value = e.target.duration;
- store.dispatch({
- type: types.SET_DURATION,
- payload: value,
- });
- };
- export const setCurrentTime = (value) => {
- audio.currentTime = value;
- return { type: types.SET_CURRENT_TIME, payload: value };
- };
- export const setVolume = (value) => {
- audio.volume = value;
- return { type: types.SET_VOLUME, payload: value };
- };
- export const toggleRepeat = (status) => {
- audio.loop = status;
- return { type: types.TOGGLE_REPEAT, payload: status };
- };
- // audio listeners
- const onEnded = () => {
- if (!audio.loop) {
- //next track if exists(if no toggle_play)
- }
- };
- const onTimeUpdate = (e) => {
- store.dispatch({
- type: types.SET_CURRENT_TIME,
- payload: e.target.currentTime,
- });
- };
- audio.addEventListener("ended", onEnded);
- audio.addEventListener("timeupdate", onTimeUpdate);
- audio.addEventListener("durationchange", setDuration);
|