I'm dynamically inserting an html5 video tag with unknown dimensions onto a page. I'm getting the dimensions with the loadedmetadata
event which works like a charm on all browsers.
However, from what I understand this event won't fire until the user touches the video on the ipad. This makes it really difficult to get the actual dimensions of the video which I need in order to size it's container.
Is there
- Another way to get dimensions of a video which would work in this scenario? or
- A way to trigger the loadedmetaevent?
Thanks!
CODE:
var src=fullPathToVideoWithoutExtension;
// DETECT WHICH FILE FORMAT TO USE
if($.support.browser.h264||$.support.mpeg4){
var supportedSRC=supportedSRC+'<source src="'+src+'.mp4" type="video/mp4">';
};
if($.support.browser.ogg){
var supportedSRC=supportedSRC+'<source src="'+src+'.ogv" type="video/ogg">';
};
// SETUP THE VIDEO ELEMENT
var $Video=$('<video id="Box_Video" controls>'+supportedSRC+'</video>');
$Video[0].src=src+'.mp4';
$Video[0].addEventListener('loadedmetadata',function(){
var width=this.videoWidth;
height=this.videoHeight;
},false)
Here's a fiddle: http://jsfiddle.net/Fv4XG/1/
Notice that in the browser it will immediately alert the video dimensions, but on the ipad you have to wait until there is user interaction before it pulls the dimensions. How can I get the dimensions when the video is inserted into the DOM like in all other browsers?