简体   繁体   English

海报不适用于带有video.js的HTML5视频

[英]Poster does not work with HTML5 video with video.js

I am trying to embed HTML video player in my webpage. 我试图将HTML视频播放器嵌入到我的网页中。 I am also using video.js to get some controls over it. 我也在使用video.js对其进行一些控制。 Here is how it looks: 外观如下:
The HTML: HTML:

<video width="100%" poster="/resources/video/video-poster.jpg" class="video-js vjs-default-skin vjs-big-play-centered" id="myvideo">
      <source type="video/mp4" src="/templates/05.mp4"></source>
      <source type="video/flv" src="/templates/05.flv"></source>
      <source type="video/webm" src="/templates/05.webm"></source>
</video>

The javascript: JavaScript:

$(function()
{
    var player_name = _V_('#myvideo');
    $(player_name).ready(function()
    {
        console.log('ready');
        player_name.addEvent('ended', function(){
            player_name.posterImage.show();
            $('.video-play').fadeIn();
            console.log('finished');
        });
    });
});

Problem is: the poster does not show up in this case. 问题是:在这种情况下,海报不显示。 If I do not use JS code, then the poster show up. 如果我不使用JS代码,则显示海报。 Seems like if try to get the player instance, 好像在尝试获取玩家实例,

var player_name = _V_('#myvideo');

then the poster does not work. 则海报不起作用。 If I remove it, poster works. 如果我将其删除,则海报有效。 I wanted to show the poster at beginning, and also after finished. 我想在开始时和完成后展示海报。 Any help? 有什么帮助吗?

One way of doing this that fits your question: 一种适合您的问题的方法:

<script type="text/javascript">
var video= $('#myvideo')[0]; 
var videoJ= $('#myvideo');        
videoJ.on('ended',function(){
    video.load();     
});
</script>

This method has the caveat to request the media URL again and depending on caching settings it may re-download the full-length media resource causing unnecessary network/CPU usage for the client. 此方法有一个警告,要求再次请求媒体URL,并且根据缓存设置,它可能会重新下载全长媒体资源,从而导致客户端不必要的网络/ CPU使用率。

A more appropriate way to solve this issue is to use and overlay image/div and bind a click/touchstart event on it to show the video tag and hide the overlay. 解决此问题的一种更合适的方法是使用并覆盖image / div并在其上绑定click / touchstart事件以显示视频标签并隐藏覆盖。 When the ended event has fired just hide the video tag and show the overlay image. 结束事件触发后,只需隐藏视频标签并显示叠加图像即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM