Controls.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import './Controls.css';
  2. import logo from './logo.svg';
  3. import Sound from 'react-sound';
  4. import {formatDuration} from './utils.js';
  5. export default function Controls({queue, error, sound, dispatch}) {
  6. const track = queue.items[queue.pos] || {};
  7. const playing = sound.playStatus === Sound.status.PLAYING;
  8. const elapsed = sound.position ? formatDuration(sound.position/1000) : '';
  9. const duration = sound.duration ? formatDuration(sound.duration/1000) : '';
  10. return (
  11. <footer className="Controls">
  12. <div className="Controls-progress">
  13. <progress className="Controls-bar" value={sound.position} min="0" max={sound.duration}></progress>
  14. </div>
  15. {duration && <span className="Controls-time">{elapsed} / {duration}</span>}
  16. {error && <span className="Controls-error">{error.code}: {error.desc}</span>}
  17. <img src={track.cover || logo} alt={track.album} />
  18. <div className="Controls-artist">{track.artist}</div>
  19. <div className="Controls-album">{track.album}{track.year && ` [${track.year}]`}</div>
  20. <div className="Controls-title">{track.no && `${track.no}. `}{track.title}</div>
  21. <div className="Controls-buttons">
  22. <button disabled={queue.pos < 1} onClick={()=>dispatch({type: 'CONTROL_PREV'})}>
  23. <svg viewBox="0 0 24 24"><g><path d="M6 6h2v12H6zm3.5 6l8.5 6V6z"></path></g></svg>
  24. </button>
  25. <button disabled={queue.pos < 0}
  26. onClick={()=>dispatch({type: (playing ? 'CONTROL_PAUSE' : 'CONTROL_PLAY')})}>
  27. {playing
  28. ? <svg viewBox="0 0 24 24"><g><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></g></svg>
  29. : <svg viewBox="0 0 24 24"><g><path d="M8 5v14l11-7z"/></g></svg>
  30. }
  31. </button>
  32. <button disabled={sound.playStatus === Sound.status.STOPPED}
  33. onClick={()=>dispatch({type: 'CONTROL_STOP'})}>
  34. <svg viewBox="0 0 24 24"><g><path d="M6 6v12h12v-12z"/></g></svg>
  35. </button>
  36. <button disabled={(queue.pos+1) >= queue.items.length} onClick={()=>dispatch({type: 'CONTROL_NEXT'})}>
  37. <svg viewBox="0 0 24 24"><g><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"></path></g></svg>
  38. </button>
  39. </div>
  40. </footer>
  41. );
  42. }