views:

453

answers:

1

I have videos playing on a new window using the video tag in HTML5. I want the size of this new window to change depending on the height and width of the video that is being played. Is there some way to do this? I am using GWT by the way.

A: 

The JavaScript you want to end up calling is window.resizeTo(h, w)

You can do this in GWT using JSNI, like so:

native void resizeWindow(int height, int width) /*-{
  $wnd.resizeTo(height, width);
}-*/;
Jason Hall
But how will I get the height and width of the video that is being played? I won't know that till after the video has started playing...or will I?
Pranabesh Sinha
The <video> element can have height and width attributes, which you can get in JavaScript using a similar JSNI approach as above. And if those aren't available, you can set them to whatever your window's h/w are.
Jason Hall
Setting the height and width to a default value will cause the video to stretch if it's default height and width are smaller. I want to obtain that default dimension of the video and then resize the window in which the video opens accordingly.
Pranabesh Sinha
If the <video> tag doesn't have a height and width defined, you can also get it in JavaScript. var height = document.getElementById('myVideo').style.pixelHeight; (and so on)
Jason Hall
document.getElementById('myVideo').style.pixelHeight is returning null. Replaced pixelHeight by clientHeight, also got null.
Pranabesh Sinha
The HTML5 spec says it should have height and videoHeight. http://www.w3.org/TR/html5/video.html
Jason Hall