Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Kavita Bargota
Kavita Bargota
2,741 Points

My audio file (mp3) does not work when uploaded onto html using the javascript code..help???

I have tried uploading an audio file onto html in the mp3 format. I want the song to play using the Javascript code which includes the button code too. I am sure enough that the code is correct but for some reason the song does not play.

I have tried uploading the audio file in different formats too (ogg and wav) WAV is too big and nothing happens with ogg.

Occasionally an error message has appeared saying it cant run the file.

can some help?

thanks

2 Answers

Kavita Bargota
Kavita Bargota
2,741 Points

Hi Christian, thank you for replying

this is the copy...but it seems to be working now...

      <hr>
    <!--Buttons-->

<center><a href="javascript:DennisBrown();"><img src="Dennis-Brown1.jpg" alt="key"></a></center> <hr> <!--Audio Files--> <audio id="DennisBrown" src="rockingtime" preload="false"></audio>

  <!--Javascript-->

<script type="text/javascript"> function DennisBrown() { document.getElementById('DennisBrown').play(); } </script>

I am not sure what was going on yesterday. I tried several different formats of the audio file.

Does the audio file always have to be in mp3?

Also the when clicked on the image (button) the song plays continously. Is there a code to start/stop?

thanks

Kavita

Christian Edmonds
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Christian Edmonds
Front End Web Development Techdegree Graduate 21,115 Points

There's a couple things that need attention.

  1. Your src attribute for your audio doesn't have a file extension. If it's a mp3 file it should read src="rockingtime.mp3" Also, double check your file path.

  2. The href attribute in your <a> element should be a JavaScript function. It should contain a url that you link to the <a>. If you want to read up on it, this might help. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

  3. And no, I'm pretty sure it'll except multiple file formats

Happy coding! You're play with some really cool stuff!