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…
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
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>
thanks! now it works!
You could just do my one liner
<button onclick="var aud=new Audio('url here');aud.play();">hi!</button>
Moved to #coding-help
Feel like this belongs in #glitch-help because he is asking a question directly about Glitch.
yeah, it does, which is why i put it in #glitch-help and not in anywhere else.
@code-alt how would you make it stop?
aud.pause();
To do this you need to make it a global var
<button onclick="aud=new Audio('url here');aud.play();">hi!</button>
I decided to do a little research, and if you want advanced features extending from Audio
, you can use the Audio Web API
how do you do that? sorry if you think i’m asking stupid questions but i really don’t know…
doesn’t really help…