summaryrefslogtreecommitdiff
path: root/app/client/common/audioPlayer/audioPlayer.reducer.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/common/audioPlayer/audioPlayer.reducer.js')
-rw-r--r--app/client/common/audioPlayer/audioPlayer.reducer.js44
1 files changed, 44 insertions, 0 deletions
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