# Play sound on server when the page is accessed



## volarepa (Dec 28, 2006)

Greetings friends.
I'm trying to do weird experiment but don't know where to start from.
I'm using debian linux and the webserver is apache.
I have created a webpage Example Domain
Is it possible to play a sound in the server computer when somebody access the page. A helping guidance is most welcome
Thanks
Volarepa


----------



## brent.charlebois (May 8, 2007)

You can implement the following code to play audio on your page:

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

mp3 files run on all browsers, whereas others don't. If you have a program that converts audio files to mp3 than use it.


----------



## brent.charlebois (May 8, 2007)

After checking on the web there are sites which will do the conversion to mp3 for you.


----------



## brent.charlebois (May 8, 2007)

Sorry about that link. I tried it again and it isn't what you want. 

Google audio converters for Linux. There are lots of sites for that.


----------



## brent.charlebois (May 8, 2007)

I'm back...the way to play music when you open a page is as follows:


```
<!DOCTYPE html>
<html>
<body onload="playAudio()">

<audio id="myAudio" loop controls>
  <source src="sound.mp3" type="audio/mp3">
  Your browser does not support the audio element.
</audio>


<script>
var x = document.getElementById("myAudio"); 

function playAudio() { 
    x.play(); 
} 

</script>

</body>
</html>
```
This has an endless loop and controls so take loop and controls out of the <audio> tag if you don't want them.


----------

