Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.39k stars 976 forks source link

Sampler doesn't load any audio from any url #1083

Closed synthwaveJunkie closed 2 years ago

synthwaveJunkie commented 2 years ago

Hello, i made a sampler but if files are in my computer, it loads samples. But i want to use an online host. I tried github, dropbox, google drive but it doesn't work.

But weirdly if use piano sounds from this url "https://tonejs.github.io/audio/casio/" it loads and plays. What am i missing? Thank you.

const hihat = new Tone.Sampler({ urls: { C3: "hh_sample.mp3", }, baseUrl: " https://github.com/synthwaveJunkie/audioFiles/", // or another url onload: () => {console.log("loaded") } });

By the way, i use sampler rather than player because gain automations cause some glitches. So i use sampler with triggerAttackRelease which has velocity parameter.

tambien commented 2 years ago

The issue is the url is not a valid audio file. If i go to the url that you are requesting (https://github.com/synthwaveJunkie/audioFiles/hh_sample.mp3) i get a 404 not found return.

Make sure you're using a file server that can serve audio files. i use github.io like you mentioned, but github.com serves webpage (html), not audio files in the same way.

synthwaveJunkie commented 2 years ago

Thank you. I created a web page "https://synthwavejunkie.github.io"
My audio files in " https://synthwavejunkie.github.io/audio/ "

if i click this, "https://synthwavejunkie.github.io/audio/hh_sample.mp3" it plays correctly. But I added this (https://synthwavejunkie.github.io/audio/ ) to sampler's baseUrl and it doesn't load. So i wrote direct link to Note, instead of using base url. Now it works!

const hihat = new Tone.Sampler({ urls: { C3: "https://synthwavejunkie.github.io/audio/hh_sample.mp3", }, onload: () => {console.log("loaded") } });

Thank you again :)