...

View Full Version : sound played by time of the day



this me
12-09-2006, 05:25 PM
i need help with this, pls
i would like to have this code play a .wav sound insted of MESSAGE DISPLAYED BY TIME OF DAY.
thanx

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>

<body>
<p><script language="JavaScript">

<!--

document.write("<center><font size=+1>")

day = new Date()

hr = day.getHours()

if (hr ==1)

document.write("Good morning! 1AM and still your going! ")

if (hr ==2)

document.write("Hey, it is past 2AM! The bars must be closed!")

if (hr ==3)

document.write("Hey, it is after 3AM! Are you a vampire or what?")

if (hr ==4)

document.write("4AM? You must roam all night huh!")

if (hr ==5)

document.write("Whoa! It's almost daylight and your still going!")

if (hr ==6)

document.write("Hey, isn't it too early to be using your computer")

if ((hr == 6) || (hr ==7) || (hr ==8) || (hr == 9) || (hr ==10))

document.write("Good Morning!")

if (hr ==11)

document.write("11AM...What are you doing surfing JavaScript pages so early??")

if (hr ==12)

document.write("NOON! Great, it must be time for me to eat breakfast!")

if (hr ==14)

document.write("It's 2PM. Have you eaten lunch yet??")

if ((hr==15) || (hr==16) || (hr==13))

document.write("Good Afternoon!")

if ((hr==17) || (hr==18) || (hr==19) || (hr==20) || (hr==21) || (hr==22))

document.write("Good Evening! Welcome to prime time on the web!")

if (hr==23)

document.write("It's almost midnight...Aren't you sleepy yet?")

if (hr==0)

document.write("It's midnight... do you ever sleep?")

document.write("</font></center>")

//--->

</script></p>
</body>

</html>

Philip M
12-09-2006, 09:29 PM
You will need to pre-load the .wav files.

<embed src="sound1.wav" hidden="true" autostart="false" name="soundfile1">

<embed src="sound2.wav" hidden="true" autostart="false" name="soundfile2">

<embed src="sound3.wav" hidden="true" autostart="false" name="soundfile3">

.... and so on

Then:-

if (hr==1) {document.soundfile1.play()}
if (hr==2) {document.soundfile2.play()}

.... and so on

this me
12-10-2006, 07:59 AM
i have tryed this code but no luck??

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>

<body>
<p><script language="JavaScript">

<!--

day = new Date()

hr = day.getHours()

if (hr==2) {document.soundfile1.play()}


<embed src="http://www.**************/games/soundfiles/the_time_is.wav" hidden="true" autostart="false" name="soundfile1">


//--->

</script></p>
</body>

</html>

Philip M
12-10-2006, 08:20 AM
The audio must be loaded before the script runs.

<body>

<embed src="http://www.**************/games/soundfiles/the_time_is.wav" hidden="true" autostart="false" name="soundfile1">

<script language="JavaScript">

day = new Date()

hr = day.getHours()

if (hr==2) {document.soundfile1.play()}

</script>

_Aerospace_Eng_
12-10-2006, 08:44 AM
FYI the play() function only works in IE.

this me
12-10-2006, 05:52 PM
i have tryed this one too but not working, and one more thing,can i do the time like this for 1:50 pm if (h==1350)? try this audio file(you need to change it, put . after www and before com)wwwhypergurlcom/games/soundfiles/the_time_is.wav

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>

<body>
<embed src="http://www.**************/games/soundfiles/the_time_is.wav" hidden="true" autostart="false" name="soundfile1">
<script language="JavaScript">

day = new Date()
hr = day.getHours()
if (hr==1) {document.soundfile1.play()}
</script>
</body>

</html>

_Aerospace_Eng_
12-10-2006, 06:03 PM
You do realize that the time has to actually be 1AM for the code to work?

this me
12-10-2006, 06:10 PM
You do realize that the time has to actually be 1AM for the code to work?
yes i do, i have the time for the one i tryed 13, for 1 pm

this me
12-11-2006, 06:43 PM
do i need to add something for the time out like?

_Aerospace_Eng_
12-11-2006, 07:23 PM
Do you have different sound files for each hour?

this me
12-11-2006, 10:58 PM
I really need your help and appreciate it, yes I do have different sound files, this is going to be a time telling code, for 24 hours a day, so I have 24 different sound files, and as I said the code doesn’t work, so do I need to add time out like 2400 or 3600?i dont see anything wrong with code

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>

<body>
<embed src="http://www.**************/games/soundfiles/the_time_is.wav" hidden="true" autostart="false" name="soundfile1">
<script language="JavaScript">

day = new Date()
hr = day.getHours()
if (hr==1) {document.soundfile1.play()}
</script>
</body>

</html>

_Aerospace_Eng_
12-12-2006, 02:07 AM
The code you are using is old and won't work in Firefox. Try this

<!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>Time by Sound</title>
<style type="text/css">
#music {
display:none;
position:absolute;
top:0;
left:0;
height:0;
width:0;
overflow:hidden;
line-height:0px;
font-size:0;
}
</style>
<script type="text/javascript">
function loadIt()
{
var thedate = new Date();
var hours = thedate.getHours();
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="http://www.yoursite.com/games/soundfiles/the_time_is_'+hours+'.wav">'
+'<param name="uiMode" value="full">'
+'<param name="autoStart" value="true">'
+'<param name="playCount" value="1">'
+'<param name="Volume" value="50">'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'showcontrols="0" uimode="full" width="1" height="1" '
+'src="http://www.yoursite.com/games/soundfiles/the_time_is_'+hours+'.wav" volume="50" autostart="1" playcount="1"> </embed>'
+'</object>';
document.getElementById('music').style.display = 'block';
}
window.onload = loadIt;
</script>
</head>
<body>
<div id="music"></div>
</body>
</html>

Be sure your sound file names are something like this

the_time_is_1.wav
the_time_is_2.wav
the_time_is_3.wav
the_time_is_4.wav
the_time_is_5.wav
etc...up to 24

this me
12-12-2006, 03:38 AM
thank you for the work,i am sorry to tell you that it wont work, here is the sound file (for the ... put items/timefile)
source,http://ia331304.us.archive.org/2/items/timefile/the_time_is_

do i have to change the .wav to mp3 format?

_Aerospace_Eng_
12-12-2006, 05:33 AM
I get a page not found at that url. Did you read what I said about naming the sound files? You need to have the numbers on the end. This should work

<!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>Time by Sound</title>
<style type="text/css">
#music {
display:none;
position:absolute;
top:0;
left:0;
height:0;
width:0;
overflow:hidden;
line-height:0px;
font-size:0;
}
</style>
<script type="text/javascript">
function loadIt()
{
var thedate = new Date();
var hours = thedate.getHours();
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="http://ia331304.us.archive.org/2/items/timefile/the_time_is_'+hours+'.wav">'
+'<param name="uiMode" value="full">'
+'<param name="autoStart" value="true">'
+'<param name="playCount" value="1">'
+'<param name="Volume" value="50">'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'showcontrols="0" uimode="full" width="1" height="1" '
+'src="http://ia331304.us.archive.org/2/items/timefile/the_time_is_'+hours+'.wav" volume="50" autostart="1" playcount="1"> </embed>'
+'</object>';
document.getElementById('music').style.display = 'block';
}
window.onload = loadIt;
</script>
</head>
<body>
<div id="music"></div>
</body>
</html>
The time now is 12amish so its 0 hours. You need to start at 0 then go to 23 sorry.

this me
12-12-2006, 06:15 AM
i am sorry that i am giving you a hard time with this, the url for the files is

http://ia331304.us.archive.org/2/items/timefile/

and yes i have changed all the names of the files, and is it becase the files are in the .wav format? i can have theme in the mp3

_Aerospace_Eng_
12-12-2006, 06:31 AM
It doesn't matter what the sound files are in. What I gave you works. I'm not sure what you are doing wrong. You haven't posted a link to your page, you keep giving invalid urls. All of your sound files are the same btw.

this me
12-12-2006, 07:18 AM
this is the same link to the sound files, it work and i updates the files so 24 is 0 for the hour 12

http://ia331304.us.archive.org/2/items/timefile/

_Aerospace_Eng_
12-12-2006, 07:35 AM
I don't need the link to the sound files. What I gave you works. If you don't believe me check out this test page.

http://pr2006.freehostia.com/test.html

Post a link to the site that you are actually putting the code on. You could be doing something wrong.

this me
12-12-2006, 09:30 AM
you know what, i dont know what is not working on my PC, so i tryed another PC that i have and it works, the sound is great, thank you very much and sorry.
it's since i upgreaded to the new wmp 11 and i have all kind of things with some it dosn't play mp3. any way thanks again. I O U

_Aerospace_Eng_
12-12-2006, 05:40 PM
I have WMP11 and it works fine so I don't know what the deal is. All I can say is reinstall WMP11 and make sure all windows applications are closed.

this me
12-12-2006, 06:42 PM
one last thing, and sorry to keep asking,how can i make this code refresh it self every hour?

_Aerospace_Eng_
12-12-2006, 11:50 PM
You really should start trying to learn these things yourself. People aren't always going to be as nice as me. There are going to be times when you need something and if you can't do it on your own then you'll have to live without it.


<!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>Time by Sound</title>
<style type="text/css">
#music {
display:none;
position:absolute;
top:0;
left:0;
height:0;
width:0;
overflow:hidden;
line-height:0px;
font-size:0;
}
</style>
<script type="text/javascript">
function loadIt()
{
var thedate = new Date();
var hours = thedate.getHours();
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="http://ia331304.us.archive.org/2/items/timefile/the_time_is_'+hours+'.wav">'
+'<param name="uiMode" value="full">'
+'<param name="autoStart" value="true">'
+'<param name="playCount" value="1">'
+'<param name="Volume" value="50">'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'showcontrols="0" uimode="full" width="1" height="1" '
+'src="http://ia331304.us.archive.org/2/items/timefile/the_time_is_'+hours+'.wav" volume="50" autostart="1" playcount="1"> </embed>'
+'</object>';
document.getElementById('music').style.display = 'block';
}
setTimeout("loadIt()",60000);
window.onload = loadIt;
</script>
</head>
<body>
<div id="music"></div>
</body>
</html>

this me
12-13-2006, 02:59 AM
thanks for the help, and the tip



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum