Skip to content
← Back to Community
How do you get a audio file to play in the index.html?
Profile icon
Dominicl645

i am collaborating with another repl.it user and i am wondering how you would get a audio file to play in the index.html.
where would i have to go and what would i code to get the audio to play?

Voters
Profile icon
SavageSpray
Profile icon
AnimeLover1069
Profile icon
cookieartist350
Profile icon
RedPandaCode
Profile icon
Dominicl645
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Try this code:

from replit import audio play('your file')

So now, all you have to do is click on the 3 dots, and get your file. And it makes a new file. Just take the name of the file and put it in the play:

Screenshot 2020-11-22 at 5.57.49 PM

That should work

Profile icon
Dominicl645

so this python code will work in HTML? @RYANTADIPARTHI

Profile icon
RYANTADIPARTHI

@dominicl645 uhh, no. If you are doing this in HTML, do it this way:

<audio controls> <source src="Your file name"> </audio

And for the file name, do the same thing, for the HTML, just click on three dots, and all.

Profile icon
Dominicl645

anyone know how to do this? pls help me

Profile icon
RedPandaCode

To get an audio file you simply need to use an tag. In side the tag you can give it a "src" attribute with the url of the audio!

<audio src="url">
Profile icon
RedPandaCode

You can also add a "controls" attribute after "src"

<audio src="url" controls>
Profile icon
Dominicl645

how would i use that code on a mp3 file already uploaded into the replit? @RedPandaCode

Profile icon
RedPandaCode

@dominicl645 Hmmm... I haven't done that before. Perhaps in "src" you may need to use the file name in repl rather than the URL

<audio src="filename.mp3" controls>
Profile icon
Dominicl645

ok i'll try it. @RedPandaCode

Profile icon
RedPandaCode

@dominicl645 Hopefully it works!

Profile icon
Dominicl645

hopefully. @RedPandaCode

Profile icon
Dominicl645

ok it wont play. @RedPandaCode

Profile icon
RedPandaCode

@dominicl645 This is what an audio should look like. See if it helps.
Screenshot 2020-11-22 at 3.50.17 PM
(Also make sure that your volume is turned up)

Profile icon
RedPandaCode

If this does not appear your code may be wrong somehow.
(This was made using the "controls" attribute)

Profile icon
RedPandaCode

Since you uploaded the file into repl, if nothing else works, try swapping the "src" attribute for an "href" attribute

<audio href="filename" controls>
Profile icon
xxpertHacker
Profile icon
littlepenguin