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

HTML5 Audio

I am trying to add audio to a page. This seems to work the best.

<audio src="Ocean_Surf.wav" autoplay id="loop-limited">
    HTML5 audio not supported
</audio>

The id is for some javascript that shuts it off once it runs through twice.

Anyway, my problem is that it stutters. I tried the following;

<audio src="Ocean_Surf.wav" autoplay preload = "auto" id="loop-limited">
    HTML5 audio not supported
</audio>

But, if anything it made matters worse because there was a large delay before playing and then it still stuttered. Any suggestions?

That's what I used recently to loop music for this game I made in javascript/jQuery on http://dodgemaster.brockswebdev.com

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

Update: Yeah, now that I hear it I guess it does kinda stutter at certain parts. I'm not sure why that is.

@brock Hmm... I had a look at your game and the audio on that is stuttering for me as well. Does it stutter for you? I think maybe the problem isn't the HTML code, but rather, the browser or my computer.

I suppose if you have a lot going on with the client-side of things, it could cause it to stutter. I notice that in my game it stutters the most when the user has to enter in the answer to the riddle. I wouldn't think that a small script would be that intensive computationally or on the browser, but who knows. Think of it like this though, have you ever tried playing windows media player and doing another task on a relatively slow computer? Music requires a lot of bandwidth and probably CPU power as well.