getting a video object's width and height

Discussion in 'JavaScript' started by lizi, Dec 29, 2011.

  1. #1
    I have embeded a video like this:
    <div class="videoDiv" id="showDis">
    <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="MediaPlayer1">  
        <param name="url" value="http://mysite/myvideo.wmv"">  
        <param name="src" value="http://mysite/myvideo.wmv"">  
        <param name="showcontrols" value="true">  
        <param name="autostart" value="true">  <!--[if !IE]>-->  
        <object type="video/x-ms-wmv" data="http://mysite/myvideo.wmv"">    
            <param name="src" value="http://mysite/myvideo.wmv"">    
            <param name="autostart" value="true">    
            <param name="controller" value="true">  
        </object>  <!--<![endif]-->
    </object>
    </div>
    Code (markup):
    I would like to retrieve the video's width and height (resolution), for example: 640x480

    how can I do that via JavaScript?

    this is what I tried:
    
    var objPlayer = document.MediaPlayer1;
    
    alert(objPlayer.offsetWidth);
    alert(objPlayer.width);
    
    
    alert(document.getElementById('showDis').style.width);
    alert(document.getElementById('showDis').style.offsetWidth);
    
    Code (markup):
    nothing gives me the real value.

    even looked here: http://msdn.microsoft.com/en-us/library/dd563945(v=VS.85).aspx but couldn't find anything relevant
     
    Last edited: Dec 29, 2011
    lizi, Dec 29, 2011 IP
  2. knewedge

    knewedge Active Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #2
    Nothing in your code contains that information, if it did you could put an id on that param and use getAttribute('height').
     
    knewedge, Jan 11, 2012 IP
  3. lizi

    lizi Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    nothing in my code contains that information because I don't know that information before hand.the video is from a source that gives a different video size every time.
     
    lizi, Jan 12, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    .offsetWidth is not an object of .style

    use this instead..
    
    alert(document.getElementById('showDis').offsetWidth);
    
    Code (markup):
     
    JohnnySchultz, Jan 19, 2012 IP