Switching streams depending on hour...

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

gotrootdude

Thread Starter
Joined
Feb 19, 2003
Messages
8,812
I'm currently using a script to stream mp3's based on the day of the week like so.

f(s_date.getDay() == 1){
document.write('<embed width=0 height=0 hidden="true" autostart="true" volume="5" loop="false" src="test.mp3">');
}

What can I use if I wish to rotate the mp3's hourly? Is there a way to get only the hour or the military time of the visit to the page?
 
Joined
Mar 28, 2004
Messages
51
Try:

var now = new Date();
var hour = now.getHours();

hour will then be the hours in military time. Then you can use an if or switch statement with hour.
 

gotrootdude

Thread Starter
Joined
Feb 19, 2003
Messages
8,812
Found it over on the msdn library: returns a value between 0 and 23.

function TimeDemo(){
var d, s = "The current local time is: ";
var c = ":";
d = new Date();
s += d.getHours() + c;
s += d.getMinutes() + c;
s += d.getSeconds() + c;
s += d.getMilliseconds();
return(s);
}
 
Joined
Jul 8, 2002
Messages
14,681
Just remember that javascript is a client-side language, so if the user's clock is set incorrectly, the wrong MP3 will be played.
 
Joined
Mar 28, 2004
Messages
51
That may not matter, though, if the purpose is just to play different MP3s instead of the same one all the time, but if the time is important, you may want to use PHP to get the hours on your server instead, if it is enabled on your server.
 
Joined
Apr 15, 2004
Messages
242
php would be my recommendation, if your server supports it.
easier to maintain too...
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top