1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Switching streams depending on hour...

Discussion in 'Software Development' started by gotrootdude, Apr 12, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. gotrootdude

    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?
     
  2. mussavcom

    mussavcom

    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.
     
  3. gotrootdude

    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);
    }
     
  4. brendandonhu

    brendandonhu

    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.
     
  5. mussavcom

    mussavcom

    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.
     
  6. dmneoblade

    dmneoblade

    Joined:
    Apr 15, 2004
    Messages:
    242
    php would be my recommendation, if your server supports it.
    easier to maintain too...
     
  7. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Its a pretty simple application, any language should be able to handle it.
     
  8. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/219823

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice