The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

43 lignes
827 B

  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. };