import types from '../../types' const audioPlayerInitialState = { loading: false, error: null, status: '', current: null, index: -1, playlist: [], } const audio = document.createElement('audio') const audioPlayerReducer = (state = audioPlayerInitialState, action) => { switch(action.type) { case types.audioPlayer.play: if (! action.file.url) { return state } audio.src = action.file.url audio.play() return { ...state, playing: true, current: action.file, } case types.audioPlayer.pause: audio.pause() return { ...state, playing: false, } case types.audioPlayer.resume: audio.play() return { ...state, playing: true, } default: return state } } export default audioPlayerReducer