使用jQuery将video加载到JW Player中

所以关注JW Player我可以加载一个video(显然)它看起来像这样:

 
Loading the player ...
jwplayer("myElement").setup({ file: "/uploads/example.mp4", height: 360, image: "/uploads/example.jpg", width: 640 });

我试图完成这样的事情,一旦模态被触发(使用jQuery)加载模态内的video:

 $("body").on('click', '[data-toggle=modal]', function(e){ var vid = $(this).attr('data-video'); jwplayer("videoElement").setup({ file: vid, width: 540 }); jwplayer("videoElement").play(); }); 

但是我收到错误: Uncaught TypeError: Cannot call method 'setup' of null

我尝试了以下其他(可能是可怕的)想法:

 $("#videoElement").jwplayer.setup({ file: vid, width: 540 }); 

 var $jwplayer = jwplayer(); $("body").on('click', '[data-toggle=modal]', function(e){ $jwplayer("videoElement").setup({ file: vid, width: 540 }); } 

但是,所有产生的结果都是Cannot call method 'setup' of null

任何指针都将非常感激。

你的页面上没有videoElement只有myElement

 
Loading the player ...

你必须使用:

 jwplayer("myElement").setup({ file: vid, width: 540 }); 

添加此脚本

  

然后像这样格式化您的链接

 Video