0

我如何调试自己的视频,因为目前没有出现警报。我用的是IE9,播放器是jwplayer。我是否遗漏了某些东西,或者我是否将用于调试的 javascript 代码放在了错误的位置,因为我试图将它放在 jwplayer 元素的下方和上方。我应该在单击播放时看到警报还是应该立即出现?

<div id="myElement">Loading the player...</div>

<?php echo 'This is the videoPath '.$dbVideoFile; ?>

<script type="text/javascript">

    jwplayer("myElement").setup({
        file: "<?php echo $dbVideoFile; ?>",
    });


var myvid = document.getElementById('myElement');
if (myvid.error) {
 switch (myvid.error.code) {
   case MEDIA_ERR_ABORTED:
      alert("You stopped the video.");
      break;
   case MEDIA_ERR_NETWORK:
      alert("Network error - please try again later.");
      break;
   case MEDIA_ERR_DECODE:
      alert("Video is broken..");
      break;
   case MEDIA_ERR_SRC_NOT_SUPPORTED:
      alert("Sorry, your browser can't play this video.");
      break;
 }
}
</script>
4

1 回答 1

0

首先,您尝试从 div 元素而不是视频中获取错误,第二件事您尝试在加载代码时立即执行此操作- jwplayer 可能在页面/文档加载时运行,或者至少在某些超时时运行,并且在那个特定的暂时还没有玩家。您应该将回调函数附加到 onError jwplayer 事件,然后尝试找出问题所在。代码常量也MediaError没有在全局范围内定义,它们绑定到MediaError对象,所以你应该使用例如MediaError.MEDIA_ERR_ABORTED而不是仅仅MEDIA_ERR_ABORTED

jwplayer("myElement").setup({
    file: "<?php echo $dbVideoFile; ?>",
    events: {
        onError: function (message) {

            console.error('Video error: ' + message);

            // note that jwplayer is replacing your original div element with new one with same id
            // you can try to get video tag created by jwplayer:
            var videos = document.getElementById('myElement').getElementsByTagName();
            if (videos.length && videos[0].error) {
                switch (videos[0].error.code) {
                    case MediaError.MEDIA_ERR_ABORTED:
                       alert("You stopped the video.");
                       break;
                    case MediaError.MEDIA_ERR_NETWORK:
                       alert("Network error - please try again later.");
                       break;
                    case MediaError.MEDIA_ERR_DECODE:
                       alert("Video is broken..");
                       break;
                    case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:
                       alert("Sorry, your browser can't play this video.");
                       break;
                    default:
                       alert('Unknown error');
                       break;
                }
            }
        }
    }
});

请参阅jwplayer 事件的文档

于 2013-01-28T13:24:33.097 回答