Click to See Complete Forum and Search --> : looping the bgsound
Sup3rkirby
10-09-2006, 01:27 PM
Is there someway to loop the bgsound object in a webpage?
I am making a script that loads some stuff, and I am using a short music clip in the background. I have very carefully edited the music so that if i loop it, it sounds smooth and clean.
But now the part i am stuck at is looping it in the webpage. I know the 'embed' object has a loop option, but it would be best if i could use the bgsound.
If it isn't possible(without using a timer in JS(which is what I am trying to do now)) then I will just try the embed object.
_Aerospace_Eng_
10-09-2006, 01:32 PM
Why do you think its best to use bgsound? You known it only works in Internet Explorer don't you?
Sup3rkirby
10-09-2006, 01:38 PM
really... well, it figures...
But anyways, from what i have noticed in the past, you can change the song in bgsound with JS, but if you try to change the src of the embed object with js, it doesn't let you...
I may be wrong, but if you can change it, then please let me know and i'll immediately switch. But i'll probably be using embed anyways... i can't stand the gap that bgsound creates when i try to loop(using a timer and js).
_Aerospace_Eng_
10-09-2006, 01:53 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Cross Browser Song Changer</title>
<style type="text/css">
body {
text-align:center;
}
#music {
position:absolute;
left:0;
top:0;
}
</style>
<script type="text/javascript">
function PlayIt(what){
document.getElementById('music').innerHTML='<object width="1" height="1" '
+'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '
+'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
+'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
+'<param name="url" value="'+what+'">'
+'<param name="uiMode" value="full">'
+'<param name="autoStart" value="true">'
+'<param name="loop" value="true">'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'showcontrols="0" uimode="full" width="1" height="1" '
+'src="'+what+'" autostart="1" loop="1">'
+'</object>';
}
</script>
</head>
<body>
<select name="player" onchange="PlayIt(this.value)">
<option value="none">::Choose a Song::</option>
<option value="http://urltosong1.mp3">Song 1</option>
<option value="http://urltosong2.mp3">Song 2</option>
<option value="http://urltosong3.mp3">Song 3</option>
<option value="http://urltosong4.mp3">Song 4</option>
<option value="http://urltosong5.mp3">Song 5</option>
</select><br>
<div id="music">
<object width="1" height="1"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">
<param name="url" value="">
<param name="uiMode" value="full">
<param name="autoStart" value="true">
<param name="loop" value="true">
<embed type="application/x-mplayer2"
pluginspage="http://microsoft.com/windows/mediaplayer/en/download/"
showcontrols="0" uimode="full" width="1" height="1"
src="" autostart="1" loop="1">
</object>
</div>
</html>
Sup3rkirby
10-10-2006, 10:25 PM
hmmm.... well, I have one thing the bgsound is good for that wmp isn't.
the 'onload' event for the body will wait for the bgsound file to be downloaded. but when it is in the wmp the 'onload' event just ignores the file download(more than likely b/c it is downloaded through the wmp plugin. so everything in HTML is loaded, but not the song since the plugin does that itself, right?)
And this was a big part of my page. there is a loading screen that is visible until everything is loaded, and this should include the song. but i can't do that with the embed(wmp plugin). So far only the bgsound will work....
any other options?
_Aerospace_Eng_
10-10-2006, 10:28 PM
Then just get rid of the object tags in between the div with id="music" and just call onload="PlayIt('blah.mp3')"
You can't always depend on others to cater to your exact needs. You have to try an implement things yourself.
Sup3rkirby
10-10-2006, 11:58 PM
You can't always depend on others to cater to your exact needs. You have to try an implement things yourself.
That's quite a bold statement.
I already designed a solution, but I didn't like the complete result. I was posting this topic here because this is a help forum where people help you and give you answers to problems relating to your web development.
I hinted at the fact that I used timers with bgsound, which is why I didn't want that as an answer.
You don't have to reply you know. Just keep in mind this is the web developer forum where users post topics asking questions to get solutions and answers to accomplish their goals online. There have been many(very many) people who just completely ask someone to do everything for them. And then it was done for them. That's just how things are gonna be around here....
rheiges
10-13-2006, 03:13 PM
I check the browser type and plugins -- and use either bgsound or embed. BUT... I have one problem I haven't been able to solve. Before I will put any kind of sound on a page I have to be able to give the viewer a way to turn it off. Firefox will take an embed (including looping) but what would be the js for turning it off?
Bob H.
Sup3rkirby
10-14-2006, 08:32 AM
I check the browser type and plugins -- and use either bgsound or embed. BUT... I have one problem I haven't been able to solve. Before I will put any kind of sound on a page I have to be able to give the viewer a way to turn it off. Firefox will take an embed (including looping) but what would be the js for turning it off?
Bob H.
Well, i've worked with the bgsound for a little while now and there are ways to work with it. And actually, the bgsound can be used to make your own media player. With the bgsound, you can change the volume and easily change the song. As far as stoping the music, you can simply provide a button that uses the following code(assuming you use 'sound' for the id of your bgsound)
document.all.sound.src = "";
Of course, the only thing you can't really do with the bgsound is pause. And recently(through a little research) I found that the bgsound has a loop option. You can choose to loop a number of times or infinitely.
Anyways, the page i am designing does not need a way to stop the music because of the type of page and the nature of the page. I can just provide a mute button for people who hate sounds, and probably will do this(because I am designing a 'flash-like' script).
And for purposes of answering this topic
<BGSOUND id="sound" src="music/song.mp3" volume="-1500" loop="infinite">
*and for anyone who needs an explaination. 'id' is set for using js to change the settings. the name doesn't really matter. 'src' is the location and filename of the sound you want to play. 'volume' is obviously the volume and is an integer between -5000 and 0. for some reason 0 is the loudest and -5000 is mute. 'loop' can be any integer 0 - infinity. if you want it to loop forever, put 'infinite'.
felgall
10-14-2006, 03:28 PM
Both <bgsound> and <embed> are proprietary tags that wont work with modern standards compliant browsers. The correct tag to use to attach objects to web pages id the <object> tag. Sound files usually work better though if they are attached to the page using the <a> tag since that way you don't drive away the large percentage of people who absolutely loathe web pages that start playing musing without asking their permission first (particularly those who just got fired from their job for visiting such a web page on work time).
Sup3rkirby
10-14-2006, 10:30 PM
Both <bgsound> and <embed> are proprietary tags that wont work with modern standards compliant browsers. The correct tag to use to attach objects to web pages id the <object> tag. Sound files usually work better though if they are attached to the page using the <a> tag since that way you don't drive away the large percentage of people who absolutely loathe web pages that start playing musing without asking their permission first (particularly those who just got fired from their job for visiting such a web page on work time).
thank you for the info(mainly about the <object> tag).
Ley me clearly state here though, I know people do NOT want music to just play on a page. And people really hate having no control over it. But for this person purpose(for which this topic was posted), music is used as a background object that is understood to be there by the user and so if the user ends up having a problem with the music on my current project, it is because they either have no common sense when they were navigating to that page, or they just don't pay any attention to the purpose of the page.
rheiges
10-15-2006, 12:26 AM
Thanks Stephen. I looked (and the wife says I could add 80 more 'and looked') at your web site link -- so far a couple of hours worth. I was particularly interested in the sound topic we are discussing here.
<http://javascript.about.com/od/guidesscriptindex/a/sound.htm>
As soon as I finish fixing my more critical 'issues' I am going to try that technique with Firefox. I am about ready to redirect Firefox users, in their complete freedom from active content and the reported 'safety' that implies, to go somewhere else. I already do that for visitors wanting to fill out a form but having javascript disabled. Not all of us have access to server-side validation.
Thanks again!
Bob