Cameron
Cameron

Reputation: 185

Play a song on HTML web page

I am trying to play a song from my Desktop. This is what I have so far...

 <audio src="Desktop/Moves.mp3" controls>
    <p>Fallback content goes here.</p>
 </audio>

I feel like something is wrong with the src but I am not sure what else to put.

Upvotes: 1

Views: 3555

Answers (2)

Johannes
Johannes

Reputation: 67738

First of all, the desktop is not a good place to put ANY file that you want to use in a website. Better put it in a subdirectory of the directory where your webpage is situated. So if your HTML page is in a folder named website, put the audio file in a folder inside that website folder, for example audio.

Second, it depends on the browser which audio file types it can handle. It's good to provide at least two formats, mp3 and ogg. Those two cover pretty much all browsers. Audacity can convert mp3 to ogg - it's free, you can find it via the search engine of your choice.

If you have those two files (i.e. the same piece of music, but two different filetypes), the code would for example look like this:

<audio controls>
  <source src="audio/Moves.ogg" type="audio/ogg">
  <source src="audio/Moves.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio> 

Upvotes: 1

DevB2F
DevB2F

Reputation: 5075

try this:

 <audio loop="loop" autoplay="autoplay">
     <source src="Desktop/Moves.mp3" type="audio/mpeg" />
 </audio>

Upvotes: 0

Related Questions