473,486 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Music in background w/ onload, function, or any other method.

Death Slaught
1,137 Top Contributor
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
Sep 14 '07 #1
11 10794
acoder
16,027 Recognized Expert Moderator MVP
That would be annoying, but here's a link.
Sep 15 '07 #2
Death Slaught
1,137 Top Contributor
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
Sep 17 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
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?
Sep 18 '07 #4
Death Slaught
1,137 Top Contributor
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
Sep 18 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
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.
Sep 19 '07 #6
Death Slaught
1,137 Top Contributor
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).



Expand|Select|Wrap|Line Numbers
  1. function play()
  2.  
  3. {
  4. window.bgsound="location";
  5. }

[HTML]<body onload="play()">
</body>[/HTML]

Thanks again, Death
Sep 19 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
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:
Expand|Select|Wrap|Line Numbers
  1. function play() {
  2. embed = document.createElement("embed");
  3. embed.setAttribute("src", "soundfile.wav");
  4. embed.setAttribute("hidden", true);
  5. embed.setAttribute("autostart", true);
  6. document.body.appendChild(embed);
  7. }
and call it onload.
Sep 20 '07 #8
helimeef
77 New Member
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.
Sep 20 '07 #9
Death Slaught
1,137 Top Contributor
Have you tried something like this:
Expand|Select|Wrap|Line Numbers
  1. function play() {
  2. embed = document.createElement("embed");
  3. embed.setAttribute("src", "soundfile.wav");
  4. embed.setAttribute("hidden", true);
  5. embed.setAttribute("autostart", true);
  6. document.body.appendChild(embed);
  7. }
and call it onload.
Thanks just what I needed.

- Death
Sep 20 '07 #10
acoder
16,027 Recognized Expert Moderator MVP
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.
Sep 21 '07 #11
acoder
16,027 Recognized Expert Moderator MVP
Thanks just what I needed.

- Death
Glad to hear you got it working. Remember to take care with sound.
Sep 21 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4545
by: Alistair Birch | last post by:
Hi I want rows of a table to appear in alternating background colours. Having looked around the web I can't find any solution apart from waiting for the next version of CSS, so I tried building...
11
3170
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
20
4385
by: gallery | last post by:
Our client insists on having a music loop playing as the visitor travels throughout his new HTML website. We will not be doing this in frames and I would prefer not to have the home page spawn...
2
7658
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
1
12313
by: Gaffer | last post by:
Is it possible to change the following code so that the music is 'off' when the page is loaded and the user gets the option to turn it on? ---------------------------------------------------...
1
2175
by: Mike | last post by:
I want to change the background image of the html page within code based on the users selection. I'm trying to use this in the page onload even response.write("<body background=' & dataitem>") ...
2
2113
by: mstearne | last post by:
Has anyone seen any Javascript that mimics the effect that allows you to browse through the New Releases, Just Added sections of the iTunes Music Store? Where you click the arrow icon and the next...
2
4389
by: ventsislav | last post by:
I want to have a background music to my simple app and a buton which plays another sound, but when I press the button the sound from it interrupts the background sound. I tried with SoundPlayer and...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.