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

General Discussion

WEBSITE AUDIO

Can a song begin to play when someone is at a website??? I am NOT talking about a video, just a song playing in the background and if so what does it take to make it happen???

4 Answers

Sure, there's a number of HTML4, 5, and Javascript ways. Google "play music on site load", for example, for particular ways.

However, be aware that there are few things that are more annoying to the average visitor than auto-loading sounds, especially if one can't turn 'em off. It's a particularly good way to make sure that someone never visits your site ever again.

Thanks For Your Input mbukhonko, it is a christian website about a christian musician. :-)

Hello Crystal,

There are some alternatives to do this with javascript but can also be done with HTML5 using the code below:

<!DOCTYPE HTML> <html> <body> <audio controls autoplay> <source src="/html5/audio.wav" type="audio/wav" /> Your browser does not support the <audio> element. </audio> </body> </html>

You can test it here http://www.tutorialspoint.com/cgi-bin/practice.cgi?file=html5-50.htm and If you would like for the player to hide, then change this in the code:

From: <audio controls autoplay>

To: <audio controls autoplay style="display:none">

I would also convert my mp3 to ogg format at http://media.io/. instead of using a wav file as in the example.

I hope this helps.

Luis

Thanks Luis, This Is AWESOME!!! :-)

Anytime!