Results 1 to 5 of 5

Thread: object playing up. Controls.isAvailable oddities

  1. #1
    Join Date
    Apr 2008

    object playing up. Controls.isAvailable oddities


    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.

    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.

    <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???

    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).


  2. #2
    Join Date
    Feb 2008
    NW Washington State
    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

  3. #3
    Join Date
    Apr 2008

    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.


    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

    Both with no replies which is disappointing.

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

  4. #4
    Join Date
    Apr 2008

    Partial Solution


    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).

    <object id="Player" width="320" height="240"
    <param name="uimode" value="none" />
    <param name="autostart" value="0" />

    Note there are a few global vars e.g. moviesID (the Player), theImage, moviesDOM.
    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 
      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.

      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; 
        uptimer = setTimeout ("oneUp()", 100); // 100 milliseconds - change this to control speed
      else {
        stepper = 0;
     function oneDown ()
      var moviesID = document.getElementById("Player");
      if (stepper < 110) {
        stepper = stepper + 10; 
        downtimer = setTimeout ("oneDown()", 100);
      else {
        stepper = 0;

    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.

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

  5. #5
    Join Date
    Feb 2008
    NW Washington State
    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

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.33348 seconds
  • Memory Usage 2,895KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates