Music in background w/ onload, function, or any other method.  | Site Addict | | Join Date: Aug 2007 Location: Tennessee
Posts: 952
| | |
I need a function that plays a song in the background ( in other words the user can't stop/start the music they have to go to another page or listen to it )
I'm not the greatest at JavaScript I don't do much with it, but I'm hoping to change that.
It doesn't really make a difference if you can do it wile the page is loading or it starts when the page is completely loaded.
Thanks, Death
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method.
That would be annoying, but here's a link.
|  | Site Addict | | Join Date: Aug 2007 Location: Tennessee
Posts: 952
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by acoder That would be annoying, but here's a link. The type of site I'm making, the users will expect music, so it wont be "annoying", and I've been to w3schools, already thats why I'm asking for a way to put it into a function.
Thanks anyway, Death
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by Death Slaught The type of site I'm making, the users will expect music, so it wont be "annoying" Maybe that should've been "could be".
I don't play much with sound, but you could try using an iframe linked to a sound file. Do you mind the sound player showing on the screen?
|  | Site Addict | | Join Date: Aug 2007 Location: Tennessee
Posts: 952
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by acoder Maybe that should've been "could be".
I don't play much with sound, but you could try using an iframe linked to a sound file. Do you mind the sound player showing on the screen? Yea I wan't it to be in the background.
Thanks, Death
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by Death Slaught Yea I wan't it to be in the background.
Thanks, Death Have a play with this. Instead of playing using a button, you could add it onload.
|  | Site Addict | | Join Date: Aug 2007 Location: Tennessee
Posts: 952
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by acoder Have a play with this. Instead of playing using a button, you could add it onload. Thanks, but it's still not what I'm looking for, I wan't the music to play in the background yes, but I wan't it in a JavaScript function, onload would be fine as long as it's something like this. (no this doesn't work it's just something i've tried). - function play()
-
-
{
-
window.bgsound="location";
-
}
[HTML]<body onload="play()">
</body>[/HTML]
Thanks again, Death
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by Death Slaught Thanks, but it's still not what I'm looking for, I wan't the music to play in the background yes, but I wan't it in a JavaScript function, onload would be fine as long as it's something like this. (no this doesn't work it's just something i've tried). Have you tried something like this: - function play() {
-
embed = document.createElement("embed");
-
embed.setAttribute("src", "soundfile.wav");
-
embed.setAttribute("hidden", true);
-
embed.setAttribute("autostart", true);
-
document.body.appendChild(embed);
-
}
and call it onload.
|  | Member | | Join Date: Sep 2007
Posts: 62
| | | re: Music in background w/ onload, function, or any other method.
Jeez okay, the last reply was probably the best recommendation. But just a few issues with making music play in the background:
1. It must not be copyrighted, or you must be the owner.
2. You better put play/pause and next/previous button, or else your users will get annoyed with the music constantly playing and restarting every time they refresh.
3. Although your users will expect to hear music, your looking at a rare audience. What about visitors? Stumblers? They have no idea your site will play music, unless you put "THIS SITE PLAYS MUSIC" in your title tag :)
Good luck.
|  | Site Addict | | Join Date: Aug 2007 Location: Tennessee
Posts: 952
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by acoder Have you tried something like this: - function play() {
-
embed = document.createElement("embed");
-
embed.setAttribute("src", "soundfile.wav");
-
embed.setAttribute("hidden", true);
-
embed.setAttribute("autostart", true);
-
document.body.appendChild(embed);
-
}
and call it onload. Thanks just what I needed.
- Death
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by helimeef Jeez okay, the last reply was probably the best recommendation. But just a few issues with making music play in the background:
1. It must not be copyrighted, or you must be the owner.
2. You better put play/pause and next/previous button, or else your users will get annoyed with the music constantly playing and restarting every time they refresh.
3. Although your users will expect to hear music, your looking at a rare audience. What about visitors? Stumblers? They have no idea your site will play music, unless you put "THIS SITE PLAYS MUSIC" in your title tag :)
Good luck. Good points. I'd say a pause/stop button wouldn't do any harm.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,750
| | | re: Music in background w/ onload, function, or any other method. Quote:
Originally Posted by Death Slaught Thanks just what I needed.
- Death Glad to hear you got it working. Remember to take care with sound.
|  | Similar JavaScript / Ajax / DHTML bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|