Can you upload music to Glitch?

I was just wondering, what if i wanted to make a project with music in it, what would I need to do to upload the music to the project? Is it even possible to add music to a project on Glitch? Sorry if this sounds like a stupid question, but I’m new to Glitch and not sure how everything is supposed to work…

1 Like

If you drag and drop the file, it should upload it into assets. Then clicking on it from there will give you a link to it

1 Like

what do you mean? i just want the music to play in the project when the project is on…not when you click something…

Add this to your script:

Upload the music you want to use on Glitch and copy the link. The fill in the values for your script.

Music is really easy to upload like png and such but you can’t play it by directly viewing unless if they used an iframe

const audio = new Audio("urlhere");
audio.play();

Or if you like one line:

new Audio("urlhere").play();

Keep in mind that these days browsers keep an annoying autoplay policy, especially for mobile users. Their browser may be configured so you cannot play audio when the page is loaded, and instead a user gesture may be required to start the audio ex. pressing a button.

Tor does that, right?

Um…ok…i’m not very familiar with Javascript…but I do know HTML…so can you please explain this a bit further?

You could use the audio tag.

<audio autoplay>
  <source src="assets link" type="audio/mp3">
  Your browser does not support the audio tag.
</audio>
2 Likes

thanks! now it works!

You could just do my one liner

<button onclick="var aud=new Audio('url here');aud.play();">hi!</button>
1 Like

Moved to #coding-help :stuck_out_tongue:

Feel like this belongs in #glitch-help because he is asking a question directly about Glitch.

5 Likes

yeah, it does, which is why i put it in #glitch-help and not in anywhere else.