Web Analytics Made Easy -
StatCounter problems with <object> - CodingForum

Announcement

Collapse
No announcement yet.

problems with <object>

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems with <object>

    First, let's start with a little story: I've been wanting to have naps at school for quite a while and I have access to a nice little room where there's a computer, a bed and no one else. The only problem is I have no alarm clock (I hate alarm clocks anyways) so I can't afford to fall asleep because I might not wake up in time for my next class. What I decided to do was to create a program that would play a specified music file at a specified time (in time to wake me up). Javascript being the only programming language I know, I decided that was the way to go.

    The real problem: So my script basically works: when I enter a time and click set alarm, it wait's till that time is reached and then, it plays the music. But I imagine I would get fed up of always being waken by the same music... So I decided to add another functionality: choosing the song. But this part doesn't work... And I really don't know why. Maybe one of you can help me? Here is my code. Also note that nothing at all works in IE, I've been programming for Firefox, I'll debugg for IE later.

    Code:
    <html>
    <head>
    <title>R&#233;veil</title>
    <style type="text/css">
    <!--
    
    .small { width: 40px; }
    div { display: none; }
    
    //-->
    </style>
    <script type="text/javascript">
    <!--
    
    function setAlarm(){
    
    var player=document.getElementById("player");
    alert(document.getElementById("filename").getAttribute("value"));
    document.getElementById("filename").setAttribute("value",document.getElementById('track').value);
    alert(document.getElementById("filename").getAttribute("value"));
    var date=new Date();
    var NOWhours=date.getHours();
    var NOWminutes=date.getMinutes();
    var NOWseconds=date.getSeconds();
    var WAKEhours=document.getElementById("H").value;
    var WAKEminutes=document.getElementById("m").value;
    var wait=(WAKEhours-NOWhours)*3600000+(WAKEminutes-NOWminutes)*60000-NOWseconds*1000;
    document.getElementById("active").setAttribute("style","display: block;");
    document.title="R&#233;veil activ&#233; pour "+WAKEhours+"heures, "+WAKEminutes+"minutes";
    var time=setTimeout("wake()",wait);
    }
    
    function wake(){
    
    document.getElementById("player").play();
    document.getElementById("playing").setAttribute("style","display: block;");
    document.getElementById("active").setAttribute("style","display: none;");
    document.title="R&#233;veillez-vous, c'est l'heure";
    }
    
    //-->
    </script>
    </head>
    <body>
    
    <div id="active">
    <h1>R&#233;veil activ&#233;, ne pas fermer cette fen&#234;tre</h1>
    <p>Pour d&#233;sactiver le r&#233;veil, tout simplement fermer cette fen&#234;tre ou changer de page.</p>
    </div>
    
    <div id="playing">
    <h1>R&#233;veillez-vous, c'est l'heure!</h1>
    <input type="button" onclick='document.getElementById("player").stop();' value="Arr&#234;ter la musique!" />
    </div>
    
    <object id="player"
    classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" autostart="false">
    <param id="filename" name="filename" value="" />
    </object>
    
    <form>
    <label for="H">&#192; quelle heure voulez-vous &#234;tre r&#233;veill&#233;?</label>
    <input type="text" id="H" value="15" class="small" />H
    <input type="text" id="m" value="5" class="small" />min.<br />
    <label for="track">Avec quelle musique voulez-vous &#234;tre r&#233;veill&#233;?</label>
    
    <input type="file" id="track" /><br />
    <input type="button" onclick="setAlarm()" value="Activer le r&#233;veil" />
    </form>
    
    </body>
    </html>
    I've highlighted the parts relative to my problem, but the problem might be elsewhere, I really don't know. (The alerts are juste there to debugg, they won't be there once I finish my script).
    Last edited by shlagish; Oct 6, 2006, 04:35 PM. Reason: I originally highlighted with Yellow... un-readable
    Shawn

  • #2
    Hmm you might be making this harder on yourself than it has to be. Are you allowed to install anything to this computer? You could install the FoxyTunes extension which has an alarm clock built into it, in which you could choose a player that will play the song for you at a set time. I use it on my laptop as an alarm clock in the morning. If you want to keep at it then keep reading, IE doesn't like it when you use setAttribute on certain attributes. Try
    Code:
    alert(document.getElementById("filename").value);
    document.getElementById("filename").value = document.getElementById('track').value;
    alert(document.getElementById("filename").value);
    Last edited by _Aerospace_Eng_; Oct 6, 2006, 07:54 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      yeah, I'm not allowed to install anything at all, unfortunately. But apart from this IE particularity, why does the script not work, even in firefox? As the two alerts show, the value of the filename parameter is indeed changing, so why wont it play it?

      The thing is, if I use this code instead:
      Code:
      <param id="filename" name="filename" value="music.mp3" />
      it plays it (after the correct amount of timing and everything). But there never seems to be a way to change which file to play..
      Shawn

      Comment


      • #4
        Okay as for it not working in Firefox, it doesn't support the play() function. Thats an IE only thing. Try it like this. It does work in IE and FF using the code below. You seemed to be overcomplicating the wait time. Get hours multiply by 3600000, get minutes multiply by 60000, add the two together and you have your wait time. The music should start playing when the wait is up. As for the filename not changing before you needed to make filename a global variable.
        Code:
        <html>
        <head>
        <title>R&#233;veil</title>
        <style type="text/css">
        .small { width: 40px; }
        div { display: none; }
        </style>
        <script type="text/javascript">
        <!--
        var filename;
        function setAlarm()
        {
        	var date = new Date();
        	var NOWhours = date.getHours();
        	var NOWminutes = date.getMinutes();
        	var NOWseconds =date.getSeconds();
        	var WAKEhours = Number(document.getElementById("H").value);
        	var WAKEminutes = Number(document.getElementById("m").value);
        	var wait = (WAKEhours * 3600000) + (WAKEminutes * 60000);
        	document.getElementById("active").style.display = 'block';
        	document.title = "R&#233;veil activ&#233; pour " + WAKEhours + " heures, " + WAKEminutes + " minutes";
        	var time = setTimeout("wake()",wait);
        }
        
        function wake()
        {
        	filename = document.getElementById('track').value;
        	document.getElementById("playerhold").style.display = 'block';
        	document.getElementById("playerhold").innerHTML = '<object width="300" height="45" '
              +'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="'+filename+'">'
              +'<param name="uiMode" value="full">'
              +'<param name="autoStart" value="1">'
              +'<param name="loop" value="true">'
              +'<embed type="application/x-mplayer2" '
              +'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
              +'showcontrols="true" uimode="full" width="300" height="45" '
              +'src="'+filename+'" autostart="1" loop="1">'
        +'</object>';
        	document.getElementById("playing").style.display = 'block';
        	document.getElementById("active").style.display = 'none';
        	document.title = "R&#233;veillez-vous, c'est l'heure";
        }
        
        //-->
        </script>
        </head>
        <body>
        <div id="active">
        	<h1>R&#233;veil activ&#233;, ne pas fermer cette fen&#234;tre</h1>
        	<p>Pour d&#233;sactiver le r&#233;veil, tout simplement fermer cette fen&#234;tre ou changer de page.</p>
        </div>
        
        <div id="playing">
        	<h1>R&#233;veillez-vous, c'est l'heure!</h1>
        	<input type="button" onclick="document.getElementById('playerhold').innerHTML = '';this.style.display = 'none';" value="Arr&#234;ter la musique!" />
        </div>
        
        <div id="playerhold">&nbsp;</div>
        
        <form>
        	<label for="H">&#192; quelle heure voulez-vous &#234;tre r&#233;veill&#233;?</label>
        	<input type="text" id="H" value="15" class="small" />H
        	<input type="text" id="m" value="5" class="small" />min.<br />
        	<label for="track">Avec quelle musique voulez-vous &#234;tre r&#233;veill&#233;?</label>
        	<input type="file" id="track" /><br />
        	<input type="button" onclick="setAlarm()" value="Activer le r&#233;veil" />
        </form>
        </body>
        </html>
        ||||If you are getting paid to do a job, don't ask for help on it!||||

        Comment


        • #5
          A few things I don't get...

          Firefox [...] doesn't support the play() function
          Firefox does support it; see example below...
          Code:
          <html>
          <body>
          
          <object id="player"
          classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" autostart="false">
          <param id="filename" name="filename" value="music.mp3" />
          </object>
          
          <input type="button" onclick='document.getElementById("player").play();' value="play" />
          
          </body>
          </html>
          So that's not the problem.. So why wont my code work?
          Also,
          Get hours multiply by 3600000, get minutes multiply by 60000, add the two together and you have your wait time
          is not good. I don't want to enter IN HOW MUCH TIME I want to be awaken, I want to enter AT WHAT TIME I want to be awaken. (ex: I want to be awaken at 15h30PM, not in 15 hours and 30 minutes) That's why I have a big calculation going on. But that part works fine

          Here is my theory as to why my method doesn't work and yours does (tell me if you think it makes sense). When the browser reads my object tag, it sets up windows media player and loads the song specified <param name="filename" value="HERE" />. So when I change that value, it doesn't change what's already loaded in windows media player... Whereas with your method, when the browser sets windows media player, it can already load the right song into it. So I guess the solution is to have the <object> created once the song is chosen.


          And well, thank you very much, after all, your script does work perfectly

          Shawn
          Shawn

          Comment


          • #6
            Well my version of FF doesn't support the play() function. I get play() function undefined in my javascript console. It really shouldn't work unless activex is installed on Firefox. Okay I see. Well alert the times you are getting. Your original code was returning negative numbers because the hour was 15 - 20 at the time (8:46pm, 20:46 your time).
            ||||If you are getting paid to do a job, don't ask for help on it!||||

            Comment

            Working...
            X