views:

2861

answers:

2

Hiya,

I'm pretty new to javascript and programming and have run into a brick wall with my project. I have a div which contains the javascript to embed a quicktime player, when the page is first loaded no .mov file is pointed at by the page so a placeholder div is 'unhidden' and the player div is set to style.display = 'none'.

So far so good, the user then enters the name of the new movie, the placeholder div is hidden and the player div is unhidden. My problem is that the javascript in the player div didn't run when the div was made visible, if I make the script for the player into a seperate function then call it when the player div is unhidden then the player runs full screen and not in the div.

I've tried using jquery to add the javascript into the div after the div is made visible but can't seem to get $("#player").load(somescript) or $("#player").html(htmlwithjavain) to add the script.

I know the player div contenst can be changed as I can use $("#player").empty(); and $("#player").html(); to manipulate it.

Thanks for reading, hope you can help

Here's the relevant code:-

Browse Media Player

            <link rel="stylesheet" type="text/css" href="CSS/browser.css" />

 <script type="text/javascript">

 <!--

            var userinterrupt=false;
            var runonce=false;

            var currentfile;
            var basemediapath = "http://10.255.10.71/IsilonBrowse/movfiles/";

            var playerheight = 750;
            var playerwidth = 900;

            var currenttc;
            var basetime;
            var baseduration;
            var currentduration = "no tc available";
            var tcoffset = 35990;

            var playspeed = 1;
            var boolisplaying=true;
            var boolonslide=false;



            //function to fire off other methods when the DOM is loaded
            //Use in place of body onload, using jquery library
            //

        $(document).ready(function()
            {
              //showEvents('jquery running');
              showhideplayer(null);
            });




          //-->
         </script>


</head>
<body onload="forceslider(); timecode()">



  <div class="container">

       <div id="timecode_container">
            <div class="tc_overlay"></div>
            <div id="timecode" class="timecode"></div>
       </div>

       <div id="player" class="playerdiv" style="display:none;">

           **javascript for player goes here...**

       </div>

       <div id="noclipoverlay" class="playerdiv" style="display:none;">
       <p>No media loaded...
       </div>

       <div id="noclipoverlay2" class="playerdiv" style="display:none;">
       <p>loading media....
       </div>

  </div>


 <div id="loadstatus"></div>
 <div id="alerts"></div>

</body>

Now the mainstuff.js file which should add the javascript code:-

         //function to switch the player div and mask div is no media file is
         //defined in the 'currentfile' variable
         //
         function showhideplayer(state)
         {

          if (!currentfile)
          {
                showEvents('wtf no media');
                document.getElementById("player").style.display = 'none';
                document.getElementById("noclipoverlay").style.display = 'block';
          }

          else if (currentfile)
          {

           document.getElementById("player").style.display = 'block';
           document.getElementById("noclipoverlay").style.display = 'none';
           showEvents('valid media file');

           }

           }

            //end of showhideplayer



         //function to change movie files, note SetResetPropertiesOnReload must be set to false
         //otherwise the B'stard player will default all attributes when setURL runs
         //
         function changemovie(newmovie)
         {
            oldfile = currentfile;
            if (newmovie == currentfile)
            {
              showEvents('same file requested so no action taken');
              return;
            }

            if (newmovie != currentfile)
            {
              showEvents('changing movie');
              //switch the divs around to hide the 'no media slide'
              document.getElementById("player").style.display = 'block';
              document.getElementById("noclipoverlay").style.display = 'none';
            }


            showEvents('movie changed to: '+newmovie);
            currentfile=newmovie;

            if (!oldfile)
            {
              $("#player").empty();
              showEvents('the old media file was blank');

              $("#player").load("/path/loadplayer.js");



            }

            document.movie1.Stop();
            document.movie1.SetResetPropertiesOnReload(false);
            document.movie1.SetURL(currentfile);

            //showEvents('movie changed to: '+newmovie);

            if (boolisplaying)
            {
              document.movie1.Play();
            }

         }

[EDIT] and here's the contents of loadplayer.js:-

            var movie1 = QT_WriteOBJECT(
        currentfile, playerwidth, playerheight, "",
        "controller","false",
        "obj#id", "movie1",
        "emb#id","qt_movie1",
        "postdomevents","True",
        "emb#NAME","movie1",
            "enablejavascript","true",
        "autoplay","true",
        "scale","aspect",
        "pluginspage","http://www.apple.com/quicktime/download/"
            );
+2  A: 

Without knowing the content of your loadplayer.js file, it will be difficult to give you a solution.

For example, if the script attempts to do a document.write() after the page has loaded, it will create a new page, overwriting the current page. Is that what you mean when you say the quicktime movie is running full screen?

Also it is generally not a good idea to load a SCRIPT element and insert it as HTML. When you add HTML to the page, jQuery finds all the SCRIPT elements and evaluates them in a global context, which might give you unexpected results.

BarelyFitz
Hi BarelyFitz,I've added the contents of loadplayer.js to the above post. I've also tried $("#player").load("/path/loadplayer.js"); to use the script, also with no success - the script doesn't run or isn't added into the div.Hi Nosreda, I didn't know I couldn't use document.getElementById as well as jQuery... this might explain why when I include jquery.js in the <head> section many other featues on the page stop working?As I say, I am a programming noob!
jon
FYI you can use document.getElementById() when you are using jQuery, but usually it's best to stick with one method of interacting with the DOM (to avoid confusion). Also jQuery library provides a layer of protection from browser differences. In your example, when you hide the player, doing $('#player').hide() would be better and more concise.
BarelyFitz
Your loadplayer.js just calls QT_WriteOBJECT() so you'll have to include that as well. As mentioned above, if that calls document.write() then that would explain your problem.
BarelyFitz
Yes you're right, when I checked the AC_Quicktime.js file it does indeed call document.write but I can get it to return a string which I'm guessing jquery can add to the div?
jon
Yes - if you can change that code, have it produce a string, which you then add to the div using .html()
BarelyFitz
Many thanks, you gave me the clue... the AC_quicktime.js library needed changing from document.write to $("#player).html('stuff for embeding movie'). Seems to work now.
jon
A: 

Use QT_GenerateOBJECTText_XHTML or QT_GenerateOBJECTText from AC_QuickTime.js if you'd like to return a string.

Darren