Soundfont js files not loading on rails 4

372 Views Asked by At

I'm somewhat new to rails (been using it for about a month), and I'm having a problem trying to get some assets loading in development. The assets are a soundfont folder that I've placed in app/assets/javascripts. It contains acoustic_grand_piano-mp3.js, acoustic_grand_piano-ogg.js, and a folder of mp3 files. The problem I'm having is when I run the server and go to localhost:3000, the page loads, but I a 404 error that acoustic_grand_piano-mp3.js failed to load because it couldn't be found. I've checked spellings multiple times. Here's the js code (from midi.js) that runs when the page loads:

window.onload = function () {
  MIDI.loadPlugin({
    soundfontUrl: "./soundfont/",
    instrument: "acoustic_grand_piano",
    callback: function() {
      var delay = 0; // play one note every quarter second
      var note = 50; // the MIDI note
      var velocity = 127; // how hard the note hits
      // play the note
      MIDI.setVolume(0, 127);
      MIDI.noteOn(0, note, velocity, delay);
      MIDI.noteOff(0, note, delay + 0.75);
    }
  });
};

Any ideas?

2

There are 2 best solutions below

0
On

I recently had a problem loading an svg asset file from my Windows Server web hosting domain. It turned out that in the IIS administration panel, a custom MIME type for svg had to be entered. (It looked like ".svg", "image/svg+xml") Before this custom type was entered, the server was giving a 404 not found on the file. Maybe the same thing happened to you?

0
On

I've been struggling with this for a while in my own app, but I recently came to a solution.

Create a folder within public, for example, public/sounds. Place within it your 3 default default MIDI sounds from the soundfonts folder - acoustic_grand_piano-mp3, acoustic_grand_piano-mp3.js, and acoustic_grand_piano-ogg.js.

Now change your soundfontUrl in MIDI.loadPlugin to "sounds/". Works in development and production for me.