The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const createAudio = sources => {
  2. const audio = new Audio();
  3. sources.forEach(({ type, src }) => {
  4. const source = document.createElement('source');
  5. source.type = type;
  6. source.src = src;
  7. audio.appendChild(source);
  8. });
  9. return audio;
  10. };
  11. const play = audio => {
  12. if (!audio.paused) {
  13. audio.pause();
  14. audio.fastSeek(0);
  15. }
  16. audio.play();
  17. };
  18. export default function soundsMiddleware() {
  19. const soundCache = {
  20. boop: createAudio([
  21. {
  22. src: '/sounds/boop.ogg',
  23. type: 'audio/ogg',
  24. },
  25. {
  26. src: '/sounds/boop.mp3',
  27. type: 'audio/mpeg',
  28. },
  29. ]),
  30. };
  31. return () => next => action => {
  32. if (action.meta && action.meta.sound && soundCache[action.meta.sound]) {
  33. play(soundCache[action.meta.sound]);
  34. }
  35. return next(action);
  36. };
  37. };