playerReducer.js 719 B

1234567891011121314151617181920212223242526272829303132
  1. export function playerReducer(state={},{
  2. type,
  3. isPlaying=false,
  4. isStopped,
  5. duration,
  6. track,
  7. // playlist: {_id, name, tracks},
  8. playlistIndex,
  9. currentTime=0,
  10. volume,
  11. }) {
  12. if (type === 'TRACK_PLAY') {
  13. return {
  14. ...state,
  15. isPlaying,
  16. isStopped: !isPlaying,
  17. };
  18. }
  19. if (type === 'TRACK_STOP') {
  20. return {
  21. ...state,
  22. isStopped,
  23. isPlaying: !isStopped,
  24. };
  25. }
  26. return state
  27. }
  28. export const actionTrackPlay = (track,isPlaying) => ({type: "TRACK_PLAY",isPlaying: track.play()})
  29. export const actionTrackStop = (track,isStopped) => ({type: "TRACK_PLAY",isStopped: track.pause()})