dimanche 28 février 2021

HTTP load failed with status 404. Load of media resource https://ift.tt/3r5kAAl failed

So i am practicing out some stuff related javascript and now at one point i need to play sounds.But the media files don't load and keeps failing everytime. I checked for some related questions where they mentioned to check the paths altho it seems to me that my path is correct since when i click on follow link it shows that audio file on VS code. I can't figure out what is going wrong.

I have not included the css part since the error is possibly in the JS or the HTML part.But i will edit if thats needed

Exact Error: "HTTP load failed with status 404. Load of media resource http://127.0.0.1:5500/kick-sound failed."

class Drumkit {
  constructor() {
    this.playBtn = document.querySelector(".play");
    this.pads = document.querySelectorAll(".pad");
    this.kickAudio = document.querySelector(".kick-sound");
    this.snareAudio = document.querySelector(".snare-sound");
    this.hihatAudio = document.querySelector(".hihat-sound");
    this.index = 0;
    this.bpm = 150;
  }
  activePad() {
    this.classList.toggle("active");
  }
  repeat() {
    let step = this.index % 8;

    this.index++;
    const activebars = document.querySelectorAll(`.b${step}`);
    //Loop over the pads
    activebars.forEach((bar) => {
      bar.style.animation = `playTrack 0.3s alternate ease-in-out 2`;
      //Check if pads are active
      if (bar.classList.contains("active")) {
        if (bar.classList.contains("kick-pad")) {
          this.kickAudio.currentTime = 0;
          this.kickAudio.play();
        }
        if (bar.classList.contains("snare-pad")) {
          this.snareAudio.currentTime = 0;
          this.snareAudio.play();
        }
        if (bar.classList.contains("hihat-pad")) {
          this.hihatAudio.currentTime = 0;
          this.hihatAudio.play();
        }
      }
    });
  }
  start() {
    const interval = (60 / this.bpm) * 1000;
    setInterval(() => {
      this.repeat();
    }, interval);
  }
}
const drumKit = new Drumkit();
drumKit.pads.forEach((pad) => {
  pad.addEventListener("click", drumKit.activePad);
  pad.addEventListener("animationend", function () {
    this.style.animation = "";
  });
});
drumKit.playBtn.addEventListener("click", function () {
  drumKit.start();
});
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Beatmaker</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <div class="sequencer">
      <div class="kick-tracker">
        <div class="controls">
          <h1>Kick</h1>
          <button data-track="0" class="mute kick-volume">
            <i class="fas fa-volume-mute"></i>
          </button>
          <select name="kick-select" id="kick-select">
            <option value="./sounds/kick-classic.wav">Classic Kick</option>
            <option value="./sounds/kick-808.wav">808 Kick</option>
            <option value="./sounds/kick-heavy.wav">Kick Heavy</option>
          </select>
        </div>
        <div class="kick">
          <div class="pad kick-pad b0"></div>
          <div class="pad kick-pad b1"></div>
          <div class="pad kick-pad b2"></div>
          <div class="pad kick-pad b3"></div>
          <div class="pad kick-pad b4"></div>
          <div class="pad kick-pad b5"></div>
          <div class="pad kick-pad b6"></div>
          <div class="pad kick-pad b7"></div>
        </div>
      </div>
      <div class="snare-tracker">
        <div class="controls">
          <h1>Snare</h1>
          <button data-track="0" class="mute snare-volume">
            <i class="fas fa-volume-mute"></i>
          </button>
          <select name="snare-select" id="snare-select">
            <option value="./sounds/snare-acoustic01.wav">Classic Snare</option>
            <option value="./sounds/snare-808.wav">808 Snare</option>
            <option value="./sounds/snare-vinyl102.wav">Snare Vinyl</option>
          </select>
        </div>
        <div class="kick">
          <div class="pad snare-pad b0"></div>
          <div class="pad snare-pad b1"></div>
          <div class="pad snare-pad b2"></div>
          <div class="pad snare-pad b3"></div>
          <div class="pad snare-pad b4"></div>
          <div class="pad snare-pad b5"></div>
          <div class="pad snare-pad b6"></div>
          <div class="pad snare-pad b7"></div>
        </div>
      </div>
      <div class="hihat-tracker">
        <div class="controls">
          <h1>Hihat</h1>
          <button data-track="0" class="mute hihat-volume">
            <i class="fas fa-volume-mute"></i>
          </button>
          <select name="hihat-select" id="hihat-select">
            <option value="./sounds/hihat-classic.wav">Classic Hihat</option>
            <option value="./sounds/hihat-808.wav">808 Hihat</option>
          </select>
        </div>
        <div class="hihat">
          <div class="pad hihat-pad b0"></div>
          <div class="pad hihat-pad b1"></div>
          <div class="pad hihat-pad b2"></div>
          <div class="pad hihat-pad b3"></div>
          <div class="pad hihat-pad b4"></div>
          <div class="pad hihat-pad b5"></div>
          <div class="pad hihat-pad b6"></div>
          <div class="pad hihat-pad b7"></div>
        </div>
      </div>
      <button class="play">Play</button>
    </div>

    <audio src="kick-sound" src="./sounds/kick-classic.wav"></audio>
    <audio src="snare-sound" src="./sounds/snare-acoustic01.wav"></audio>
    <audio src="hihat-sound" src="./sounds/hihat-acoustic01.wav"></audio>
    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/js/all.js"
      integrity="sha512-lG4ecFD33e8IENm9b2zEBGaYRXNoPlPFekN8Dlk5NXx5PrrkuVGt2cm9yeSliyKVUIeI10f8NLMO/493qeJcBg=="
      crossorigin="anonymous"
    ></script>
    <script src="./app.js"></script>
  </body>
</html>



Aucun commentaire:

Enregistrer un commentaire