I am using modal box of bootstrap to load videos using videojs. I need to fetch the video file name from database.
When someone clicks on a link, a playVideo()
function is called.
What I do is that I populate a div with id videoPlayer and populate it with the video code.
Here is my playVideo function:
function playVideo(id)
{
$('video').attr('id','CurrentVideo'+id);
var videoData=new Array();
$.getJSON('<?PHP echo base_url();?>admin/content/getVideoDetail/'+id,function(data){
$.each(data,function(k,v){
videoData.push(v);
});
}).done(function(){
$("#videoPlayer").html('<video id="CurrentVideo'+id+'" class="video-js vjs-default-skin" controls width="530" height="264" preload="none"> <source type="video/mp4" src="<?PHP echo base_url()?>content/videos/'+videoData[3]+'"></video>');
myPlayer=_V_('CurrentVideo'+id);
$("#videoBox").modal();
$("#videoBox").on('hide',function(){
$("#videoPlayer").html('');
});
});
}
This works sometimes but is not working very consistently in all browsers. Have i taken a wrong approach? Further, is there any flaw with videojs? should i use some other alternative like flowplayer?