ellescuba27
Member
- Messages
- 273
- Reaction score
- 3
- Points
- 18
NOTE: Before I start with anything I am going to give you a good warning. I am going to give an example of how to create autostarting sounds but highly recommend AGAINST doing so. That is, sounds that play when the page loads. Users listen to music while browsing sites and autostarting sounds or music is really annoying because they clash. Don't, please. And do not use copyrighted sounds, you probably have a good idea why.
Ok, now that that's out of the way, let's look at some practical uses for sounds on a website. You could be a music studio looking to put 30 second previews on your site, or have a small click noise when you press a link, or maybe you are creating a videogame like a replica of Mario Bros. and want to have a classic chiptune playing the the background. Whatever the case, you have a few choices.
1. Embed plugins
2. Flash
3. Bgsounds
Let's look at the first one, embed plugins. If you know HTML, you probably know of the <embed> tag. This can be used to play sounds. First, though, the browser needs to know what player to use to play these sounds. This can be done with mimetypes. That is done with the type attribute. Let's add that to the <embed> tag:
<embed type=""></embed>
^
What are we going to put in that blank space?
Mimetypes tell the browser what type of file you are playing. For example, with mp3s, you could use audio/mpeg . You need to look up the proper mimetype for your format.
<embed type="audio/mpeg"></embed>
If you use a mimetype for a certain format, such as audio/mpeg , it is up to the user to decide what we can open the file with. VLC Player, Quicktime, Windows Media Player, and Realplayer are all examples. If we want to force a specific player, sometimes they even have a mimetype specific to themselves.
VLC Player: application/x-vlc-player
Windows Media Player: application/x-mplayer2
Quicktime: video/quicktime
Realplayer: audio/x-pn-realaudio-plugin
The next step is telling the browser what file to play. Let's use song.mp3 . We can use the src attribute for this (src stands for source).
<embed src="song.mp3" type="audio/mpeg"></embed>
Great! Now, the width and height. Specified in either percent or pixels like with an <img> tag.
<embed src="song.mp3" width="32" height="32" type="audio/mpeg"></embed>
If the width or height is set to 0, some browsers, like Firefox, do not play the sound. Set it to 1 instead.
Now the autostart attribute. Once again I bring up you should not use this unless it is an absolute emergency, I cannot think of a good example.
autostart="false" <- set it to true or false
And the loop attribute says whether or not the sound should play twice.
loop="true" <- again, true or false
And, similar to the autostart and loop attributes, the hidden attribute makes your sound invisible. I recommend leaving it visible so users can choose to turn it off. This attribute once again does not work in some browsers (Firefox is one).
The volume attribute, from 0 to 100 - pretty self explanatory
volume="50" sets it to half volume
<embed src="song.mp3" width="32" height="32" volume="50" autostart="false" loop="true" hidden="false" type="audio/mpeg"></embed>
Hiding the controls is tough because it varies from player to player. For Quicktime, it is:
controller="false"
Windows Media Player:
showcontrols="0"
Realplayer does it a bit differently. It comes without controls by default. To add them, you must add another embed tag linked to the first one. So in the actual video tag, add:
controls="imagewindow" console="c[add thirteen random numbers]"
And later, add
<br><embed type="audio/x-pn-realaudio-plugin" src="[same as the first one]" width="[same as the first one]" height="26" autostart="true" controls="ControlPanel" console="c[same thirteen random numbers as before]"></embed>
This will link them together and add controls.
If you want to go even further and really make users angry because they can't click the video to pause it without controls, add this:
href="javascript:"
Another note: I know javascript: should be avoided but for this purpose that is the only way to pull this off.
So a player with absolutely no way of controlling looks something like
<embed src="song.mp3" width="32" height="32" volume="50" controller="false" href="javascript:" autostart="false" loop="true" hidden="false" type="audio/mpeg"></embed>
Note that in Quicktime the controls take up 16 pixels of space.
This post has already taken up some space so the next one will be about Flash and Bgsounds.
Ok, now that that's out of the way, let's look at some practical uses for sounds on a website. You could be a music studio looking to put 30 second previews on your site, or have a small click noise when you press a link, or maybe you are creating a videogame like a replica of Mario Bros. and want to have a classic chiptune playing the the background. Whatever the case, you have a few choices.
1. Embed plugins
2. Flash
3. Bgsounds
Let's look at the first one, embed plugins. If you know HTML, you probably know of the <embed> tag. This can be used to play sounds. First, though, the browser needs to know what player to use to play these sounds. This can be done with mimetypes. That is done with the type attribute. Let's add that to the <embed> tag:
<embed type=""></embed>
^
What are we going to put in that blank space?
Mimetypes tell the browser what type of file you are playing. For example, with mp3s, you could use audio/mpeg . You need to look up the proper mimetype for your format.
<embed type="audio/mpeg"></embed>
If you use a mimetype for a certain format, such as audio/mpeg , it is up to the user to decide what we can open the file with. VLC Player, Quicktime, Windows Media Player, and Realplayer are all examples. If we want to force a specific player, sometimes they even have a mimetype specific to themselves.
VLC Player: application/x-vlc-player
Windows Media Player: application/x-mplayer2
Quicktime: video/quicktime
Realplayer: audio/x-pn-realaudio-plugin
The next step is telling the browser what file to play. Let's use song.mp3 . We can use the src attribute for this (src stands for source).
<embed src="song.mp3" type="audio/mpeg"></embed>
Great! Now, the width and height. Specified in either percent or pixels like with an <img> tag.
<embed src="song.mp3" width="32" height="32" type="audio/mpeg"></embed>
If the width or height is set to 0, some browsers, like Firefox, do not play the sound. Set it to 1 instead.
Now the autostart attribute. Once again I bring up you should not use this unless it is an absolute emergency, I cannot think of a good example.
autostart="false" <- set it to true or false
And the loop attribute says whether or not the sound should play twice.
loop="true" <- again, true or false
And, similar to the autostart and loop attributes, the hidden attribute makes your sound invisible. I recommend leaving it visible so users can choose to turn it off. This attribute once again does not work in some browsers (Firefox is one).
The volume attribute, from 0 to 100 - pretty self explanatory
volume="50" sets it to half volume
<embed src="song.mp3" width="32" height="32" volume="50" autostart="false" loop="true" hidden="false" type="audio/mpeg"></embed>
Hiding the controls is tough because it varies from player to player. For Quicktime, it is:
controller="false"
Windows Media Player:
showcontrols="0"
Realplayer does it a bit differently. It comes without controls by default. To add them, you must add another embed tag linked to the first one. So in the actual video tag, add:
controls="imagewindow" console="c[add thirteen random numbers]"
And later, add
<br><embed type="audio/x-pn-realaudio-plugin" src="[same as the first one]" width="[same as the first one]" height="26" autostart="true" controls="ControlPanel" console="c[same thirteen random numbers as before]"></embed>
This will link them together and add controls.
If you want to go even further and really make users angry because they can't click the video to pause it without controls, add this:
href="javascript:"
Another note: I know javascript: should be avoided but for this purpose that is the only way to pull this off.
So a player with absolutely no way of controlling looks something like
<embed src="song.mp3" width="32" height="32" volume="50" controller="false" href="javascript:" autostart="false" loop="true" hidden="false" type="audio/mpeg"></embed>
Note that in Quicktime the controls take up 16 pixels of space.
This post has already taken up some space so the next one will be about Flash and Bgsounds.