Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy sound played by time of the day

    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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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>

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    FYI the play() function only works in IE.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Last edited by this me; 12-10-2006 at 06:59 PM.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You do realize that the time has to actually be 1AM for the code to work?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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
    Last edited by this me; 12-10-2006 at 06:15 PM.

  • #9
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do i need to add something for the time out like?

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Do you have different sound files for each hour?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Last edited by this me; 12-11-2006 at 11:20 PM.

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The code you are using is old and won't work in Firefox. Try this
    Code:
    <!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
    Code:
    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
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/ite...e/the_time_is_

    do i have to change the .wav to mp3 format?
    Last edited by this me; 12-12-2006 at 03:43 AM.

  • #14
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Code:
    <!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.
    Last edited by _Aerospace_Eng_; 12-12-2006 at 05:37 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #15
    New Coder
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by this me; 12-12-2006 at 06:21 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •