在JW Player中自动播放视频

时间:2011-03-17 17:26:08

标签: video jwplayer

我正在尝试使用JW Player(V 4.2.88)在页面加载时播放.flv视频 即使我的代码看起来没问题,我也无法在页面加载时自动播放代码。

我也得到播放器为空或不是IE中的对象。如果我添加一个按钮并在其上点击Play(),则视频开始播放。

我正在使用JQuery,.NET 4.0& C#

这是我的代码:

<script type="text/javascript">
      var player;
      function playerReady(thePlayer) {
         //this gets fired in IE, FF
         player = window.document[thePlayer.id];         
      }
      function createPlayer() {
         var flashvars = { autostart: "true", skin: "http://localhost/app/Binn/flv/modieus.swf", lightcolor: "33cc00", frontcolor: "cccccc", quality: "true" }
         var params = { allowfullscreen: "true", allowscriptaccess: "always", wmode: "opaque" }
         var attributes = { id: "player1", name: "player1" }
         swfobject.embedSWF("/app/Binn/flv/player.swf", "VPlayer", "717", "420", "10.0.1", false, flashvars, params, attributes);
      }      

      function Play() {
         //this line gives error in IE saying player is null or not an object
         player.sendEvent('LOAD', 'http://localhost/kvs/u/bob/soccer.flv');
      }
      $(function () {
         alert('Creating the player on page load');
         createPlayer();
      });
      $(window).load(function () {
         alert('window loaded, so auto playing video');
         Play();
      });
   </script>

<div id="VPlayer"></div>

1 个答案:

答案 0 :(得分:0)

花了几个小时后我找到了空问题的解决方案......

您可以通过添加“&amp; nbsp;”来防止出现空错误在容器中的div标签之间:

<div id="container">&nbsp;</div>

这很有趣,但解决了我的问题...