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.
Results 1 to 10 of 10

Thread: Timing music?

  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Timing music?

    Hello, I'm wonder if theres anyway I can script my music to start playing at a particular time (ex. 8:00PM). What I want to happen is that the music loads with the page but doesnt play till a specified time.

    I have a chatroom on my website and we have a special event coming up. I need the music to start at a particular time and start at the same time for everyone that will be attending.

    Thanks for any help! I would appreciate an anwer ASAP as the event is tomorrow night!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    <SCRIPT>
    var now = new Date();
    var utchh = now.getUTCHours();
    var mm = now.getMinutes();
    </SCRIPT>

    <EMBED src="themusicfile.mid" name="soundfile1" autostart="false" hidden="true">
    <p><a href="#" ONMOUSEOVER="javascript:if (utchh >=20 && mm >= 0) {document.soundfile1.play()}">Mouseover Here to make sound</a></p>

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, thanks so much! Question though-what do I need to edit/add in? Sorry-I'm unfamiliar with this coding-just know where to put it! Like where do I put the time in and how do I type the time.

    The actural time i need is 8:00PM, so if you could help me out I would really appreciate it.

    Also- when it says "Mouseover Here to make sound" does that mean it wont play unless the mouse is over the link? How does the scrpit work? I want it to just start playing by itself at 8:00 for everyone.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Put

    if (utchh >=20 && mm >= 0){
    document.soundfile1.play()
    }


    in a function in the script and run it onload
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #5
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now you just have me confused. What is the full script I need to add to my HTML in order to have the music play at 8:00PM tonight? I can change the music filename myself.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    if (utchh >=20 && mm >= 0){
    document.soundfile1.play()
    }

    The time is in 24-hour clock. 8.00pm is 2000 hours.
    That is 20 hours 00 minutes.

    utc time is universal time, i.e. the same time anywhere regardless
    of time zones (which I imagine is what you want).

    && mm>= 0 is not stictly required here - I only put it in so
    that you could make it play at (say) 2015 or whatever if you wished.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Mr J's solution will only work if the page is loaded at or after 2000. We need to monitor the time and then play the sound (once only) at 2000 (local time). The sound will not play if the page is loaded at 2001 or after.

    This should do it:

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var timerID = null;
    var timerRunning = false;
    var played = 0;
    function stopclock (){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;
    }
    function showtime () {
    var now = new Date();
    var hours = now.getHours();
    var mins = now.getMinutes();
    if (hours == 20 && mins == 0 && played == 0) // alter 20 to test the script off line.
    {
    document.soundfile1.play()
    played = 1;
    }
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;
    }
    function startclock() {
    stopclock();
    showtime();
    }
    // -->
    </SCRIPT>

    Copy the above script into the HEAD section of your HTML file.

    Add this onLoad event handler to the BODY tag :-

    <BODY onLoad="startclock()">

    and of course

    <EMBED src="themusicfile.mid" name="soundfile1" autostart="false" hidden="true">
    Last edited by Philip M; 10-21-2005 at 08:29 AM.

  • #8
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually as I read the last code... I think that the setTimeout should point to startclock() not showtime()... startclock runs both stopclock (which will shut off the timer after 8) and showtime (which plays the music at 8, or checks in another second to see if it's 8)

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Mr J's solution will only work if the page is loaded at or after 2000.
    Not really my solution so I suppose it's your mistake as well Philip M, see post #2

    When Thoer said

    Also- when it says "Mouseover Here to make sound" does that mean it wont play unless the mouse is over the link? How does the scrpit work? I want it to just start playing by itself at 8:00 for everyone.
    I just pasted the part of importance to point out that it would have to run onload instead of onmouseover, but I did assume it was from 2000 hrs and not at 2000hrs
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by Pyth007
    Actually as I read the last code... I think that the setTimeout should point to startclock() not showtime()... startclock runs both stopclock (which will shut off the timer after 8) and showtime (which plays the music at 8, or checks in another second to see if it's 8)
    Yes, thank you for pointing that out!

    Like Mr J, I originally read it that the sound was to play AT OR AFTER 2000 rather than just AT 2000.


  •  

    Posting Permissions

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