www.webdeveloper.com
Results 1 to 5 of 5

Thread: object playing up. Controls.isAvailable oddities

  1. #1
    Join Date
    Apr 2008
    Posts
    7

    object playing up. Controls.isAvailable oddities

    Hi,

    My second major attempt to get video working without a control panel. I need to play, stop, step etc programmatically. Using IE7 and FF2 but obviously need all browsers to work (except perhaps really old versions).

    I've tried countless methods but all fall short when it comes to allowing me to control the video with my own javascript. Initial main problem (at least in IE7) is the Player.URL = videoname; automatically starts the video even with autostart param set to false (also tried 0). Thereafter, the availability of the controls appears to depend on some timing issue. E.g. if I test for isAvailable ('currentPosition') the code says no but actually setting currentPosition works.

    I've also had endless problems with changing settings that help the code to work in IE but then break FF e.g.

    Code:
    moviesID.windowlessVideo = true; // doing this in JS instead of object appears to help IE but break FF
    //Or for balance   
    moviesID.uiMode = "none";  // this worked as FF param but not IE param

    Sadly, my last attempt was in June (more or less all of June) and it is a while ago so cannot recall all details but the document.write approach seemed to be much easier to work with. I've missed out the test for IE/FF and FF object setup but you can see that in the msdn link provided. I want to avoid the embed approach as it is deprecated.

    I tested this in w3schools TryIt (kind of handy for a quick cut and paste) and video link came from there. (Reason I mention this is because the video is WMV v8 and I've also tried WMV v7 and v9 files). My WMP is at v11.

    Code:
    <html>
    <body>
    
    <h2>Playing The Object</h2>
    
    <script type="text/javascript">
    // based on technique in 
    // http://msdn.microsoft.com/en-us/library/bb614509(VS.85).aspx
    // this approach (document.write) did seem to help but not sure why       
    
        document.write('<object id="Player"');
        document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
        document.write(' type="application/x-oleobject"');
        document.write(' <param name="autostart" value="false" />');
        document.write(' width=320 height=240></object>');
    
      moviesID = document.getElementById("Player");
    
      
      moviesID.windowlessVideo = true;
      moviesID.stretchToFit = true; // make it fit window
      moviesID.uiMode = "none";  // this worked as FF param but not IE param
      //movies.autoStart = 0;
      var theImage="http://www.ananova.com/about/vap_windows_check.wmv";
      //movies.autoStart = false;
    
      moviesID.URL = theImage;
      //moviesID.controls.stop(); // when comments removed different controls
      // become available. E.g. with no stop quickly clicking alerts the 'play'
      // alert is not shown. But, if the video is allowed to complete before click
      // okay then the 'play' alert is reached... 
      //If the movies is stopped above then the 'stop detected' is never reached
    
      if (moviesID.controls.isAvailable("stop") )
        alert ("stop detected");  // stop never detected
      if (moviesID.controls.isAvailable("play") )
        alert ("play detected");  // play never detected
      if (moviesID.controls.isAvailable("currentPosition") )
        alert ("current position detected"); // currentPosition never detected
    
      moviesID.controls.currentPosition = 2; // but it works - change this 0-3
      moviesID.controls.play(); // Movie starts due to URL being set???
    
    </script>
    
    </body>
    </html>

    To re-iterate I've tried dozens of combinations of object/embed/clsid and countless combinations of parameters. Nothing seems to work reliably (sometimes running a 'dummy' video helped expose the controls properly for the real run but not ideal).

    In summary, I have autostart set to false. I set the URL for the video and expect to be able to control the video via play but it charges off instantly and only some of the controls are available (and when they are sometimes isAvailable says they are not).


    Regards
    srsm

  2. #2
    Join Date
    Feb 2008
    Location
    NW Washington State
    Posts
    1,856
    Don't know much about javascript but it would be interesting to see how you resolve this. Just what do you mean "control programmatically"? Are you setting certain conditions that fire an action? What I don't understand is if I'm viewing the video in my browser, what conditions do you want to control as I watch the video? Are you waiting for my input and then depending on that, the video plays, stops, or jumps to a certain frame?
    Eye for Video
    www.cidigitalmedia.com

  3. #3
    Join Date
    Apr 2008
    Posts
    7
    EfV

    I've added a small example within the code - see the setting of currentPosition (number of seconds from start). Here it is hardcoded to 2 seconds but you can copy the code and have a go.

    Try
    http://www.w3schools.com/media/tryit...videoaviobject

    Now copy in my code and press the "edit the text and Click me".
    This should run my version. Obviously doesn't do anything sensible at the moment as this is just some short test code that shows the problem with alerts etc to show what functions the Player Object has made available. Try changing the 2 seconds to 1 or 3. The video starts where you tell it to start. Also uncomment the line with the stop on it and click the alerts okay buttons while the video is playing and after it has stopped (you may only hear the sound). Weird stuff happens.

    My guess is that the WMP object exposes different functionality at different times. In this case the autostart = false is ignored and so setting the Player.URL causes the video to start. Also isAvailable is only available at certain states.

    Imagine if that value came from a slider or a dial or just a text box. I've also figured out how to play the video forwards/backwards using step(). And with timer settings can play at any speed I like (imagine an editing suite where you turn a dial to move a frame at a time). It should all be possible without endless grief... and this is what I need to do.

    These poor souls have had similar troubles
    http://www.webdeveloper.com/forum/sh...layer.controls
    http://www.webdeveloper.com/forum/sh...layer.controls

    Both with no replies which is disappointing.

    I will most certainly post a fix if I find it.
    Cheers
    srsm

  4. #4
    Join Date
    Apr 2008
    Posts
    7

    Partial Solution

    Update

    Using document.write to build the object doesn't work in this context. There needs to be a delay before the object has initiated (guess). Oddly, the impact neatly simulates the problems I have been having (which is why I missed it when building up my mock-up test code).

    I've made considerable progress on account of ignoring isAvailable and setting delays after many of the control operations. I now have a cascade of functions which firstly setup the player with uiMode URL etc but in a special way to cope with IE/FF inconsistencies - initMovie() then I Play the video followed by a setTimeout to the next function.

    getDuration(). This captures the player.currentMedia.duration and sets the currentPosition and then another short delay before...

    videoPositioned(). All this took place off screen using absolute positioning. Now that most of the work is done move on screen and then Play the video again (this to force the video to apply the set currentPosition) then another delay (which sadly needs to be quite long. Currently set to 500 milliseconds. Get this wrong and on FF the video will appear only randomly... yikes. Note the commented out but handy method for passing a parameter with a setTimeout. This calls...

    videoReady(). Which simply pauses to enable the operator to decide what to do with the video. For example I use controls.step(1) to move one frame at a time and use setInterval (with some logic to know when to quit) to move slowly forwards/backwards (step(-1)) a frame at a time. Changing the delay changes the video speed (I should be able to do let the user modify this speed too). See code below.


    I know this is total madness but it looks as though it will work. I need to do more to hide the video in some way until it has paused (I also set the volume to 0 when not testing). I've also recalled the advice to use FLV but these were equally hellish to use in particular TGoto TStop etc. I don't have any of the really expensive tools so that didn't help.

    Setting up the object like this should do it (not FF version - see previous posts).

    Code:
    <object id="Player" width="320" height="240"
    classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"
    type="application/x-oleobject">
    <param name="uimode" value="none" />
    <param name="autostart" value="0" />
    </object>

    Note there are a few global vars e.g. moviesID (the Player), theImage, moviesDOM.
    Code:
    function initMovie (showMe) {
       // start video to expose functions
      moviesID = document.getElementById("Player");
    
    if (browser == "IE") {
        moviesDOM.style.bottom = "70px"; // simple solution to IE hiding icons
        // http://msdn.microsoft.com/en-us/library/bb249373(VS.85).aspx  Only set at design time and upsets Vista!!!
        moviesID.windowlessVideo = true; // doing this here instead of object appears to help IE but break FF
        moviesID.stretchToFit = true; // make it fit window
      }
      moviesID.uiMode = "none";  // this worked as FF param but not IE param - vital for IE here
      //moviesID.settings.volume = 0; 
    
      theImage = "full http//pathtovideootherwiseFFgetsupset" + showMe;
      //theImage = "mms://wm.microsoft.com/ms/msnse/0410/23725/PhotoStory/Photostory_demonstration_MBR.wmv";
      moviesID.URL = theImage;
      moviesID.controls.play();   // in FF the first time around the play doesn't work unless the entire path is provided 
      
      // wait an interval to allow to start then proceed in next function
      setTimeout ("getDuration()", 500); // Need a pause or currentMedia.duration won't be available
      }
    
    function getDuration () {
      var duration = moviesID.currentMedia.duration;
      moviesID.controls.currentPosition = Math.floor(duration / 2); // cP needs to come just before play - just put to middle of video for a test
      setTimeout ("videoPositioned ()", 15); // need to allow time for play to start 
      // FF needs just a 1 millisecond delay (plus function call losses).
      // IE needs around 15 milliseconds 
    }
    
    function videoPositioned () {
      // from http://www.makemineatriple.com/2007/10/passing-parameters-to-a-function-called-with-settimout/
      //setTimeout(function(){myFunction(parameter); parameter = null},myTimeout);
    
      moviesDOM.style.left = "10px"; // video was tucked away out of sight - need to do this here or FF gets upset
      // now play - and delay to allow play to settle 
      moviesID.controls.play();  
      setTimeout ("videoReady()", 500); // need to allow time for play to start 
      // 5:40pm 5th August Video starts and pauses at midpoint in both IE and FF.
      // longer pause here helped (was 15 now 500). Perhaps this can be lowered but problem intermittent so hard to test
      // IE still hides the elements that should float on top of the video (FF great)
      }
    
    function videoReady () {
      // now pause - the movie is ready to play with...
      moviesID.controls.pause ();
      }

    Code to move slowly through the video in either direction. Stepper is global to hold state outside potential infinite loop. A really nice sense of control is obtained. Much better than the clumsy sliders on the player itself.

    Code:
      function oneUp ()
      {// First call to oneUp appears not to work. Press Up button again - works fine thereafter 
      var moviesID = document.getElementById("Player");
      if (stepper < 110) {
        stepper = stepper + 10; 
        moviesID.controls.step(1);
        uptimer = setTimeout ("oneUp()", 100); // 100 milliseconds - change this to control speed
        }
      else {
        stepper = 0;
        clearTimeout(uptimer);
        }
      }
    
     function oneDown ()
      {
      var moviesID = document.getElementById("Player");
      if (stepper < 110) {
        stepper = stepper + 10; 
        moviesID.controls.step(-1);
        downtimer = setTimeout ("oneDown()", 100);
        }
      else {
        stepper = 0;
        clearTimeout(downtimer);
        }
      }

    This took weeks of mind numbing effort (and may not be complete). The Flash approach was just as bad. This can't be how the WMP is meant to be controlled - I'm sure I've missed something which will blow all this nastiness away.

    Hope someone can make use of it or explain why I need to go to such lengths.

    Cheers
    srsm
    Last edited by srsm; 08-05-2008 at 02:26 PM.

  5. #5
    Join Date
    Feb 2008
    Location
    NW Washington State
    Posts
    1,856
    Looks like you are getting things worked out a little at a time. Good job!
    Being more of a Flash developer I recognize many of the attributes from ActionScript but it looks like you are taking this to new levels for WMP.
    Keep on Truckin,
    Eye for Video
    www.cidigitalmedia.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles