...

View Full Version : Timing music?



Thoerr
10-20-2005, 01:35 AM
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!

Philip M
10-20-2005, 09:20 AM
<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>

Thoerr
10-20-2005, 10:16 PM
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.

Mr J
10-20-2005, 10:26 PM
Put

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


in a function in the script and run it onload

Thoerr
10-20-2005, 10:45 PM
:confused: 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.

Philip M
10-21-2005, 07:57 AM
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.

Philip M
10-21-2005, 08:23 AM
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">

Pyth007
10-21-2005, 01:56 PM
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)

Mr J
10-21-2005, 02:02 PM
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 :o

Philip M
10-21-2005, 02:40 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum