Skip to content

Instantly share code, notes, and snippets.

@kaitwalla
Last active August 29, 2015 13:59
Show Gist options
  • Save kaitwalla/10747012 to your computer and use it in GitHub Desktop.
Save kaitwalla/10747012 to your computer and use it in GitHub Desktop.
VideoJS dynamic load
function makeVid(vidSrc,width,height,poster,id,div) {
if (typeof vidSrc === 'undefined') {
console.log('You need to include a video source in order to call a video');
return false;
}
div = typeof div !== 'undefined' ? div : 'body';
width = typeof width !== 'undefined' ? width : 640;
height = typeof height !== 'undefined' ? height : 480;
poster = typeof poster !== 'undefined' ? poster : 'none';
id = typeof id !== 'undefined' ? id : 'player' ;
var attributes = {
'id': id,
'class': 'video-js vjs-default-skin',
'width': width,
'height': height,
'controls': '',
'poster':poster,
'preload':'auto'
};
source = document.createElement('source');
$(source).attr('type','video/mp4');
$(source).attr('src',vidSrc);
obj = $('<video />').attr(attributes);
$(div).append(obj);
$(obj).append(source);
_V_(document.getElementById('player'+id));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment