From 91c47c22f2c71c524fd665f19186bb014c94ab31 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Jun 2018 04:50:27 +0200 Subject: audioplayer you can toggle --- .../common/audioPlayer/audioPlayer.reducer.js | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/client/common/audioPlayer/audioPlayer.reducer.js (limited to 'app/client/common/audioPlayer/audioPlayer.reducer.js') diff --git a/app/client/common/audioPlayer/audioPlayer.reducer.js b/app/client/common/audioPlayer/audioPlayer.reducer.js new file mode 100644 index 0000000..e249325 --- /dev/null +++ b/app/client/common/audioPlayer/audioPlayer.reducer.js @@ -0,0 +1,44 @@ +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 -- cgit v1.2.3-70-g09d2