简体   繁体   English

悬停播放HTML5视频,导致海报无法显示,视频延迟

[英]Play HTML5 video on hover causing poster to not show, video delayed

Ok, have a strange problem here that i'm hoping someone will be able to shed some light on. 好的,这里有一个奇怪的问题,我希望有人能够对此有所启发。 The site in question is here: http://tlt.voltronik.co.uk - Please scroll down to the Latest Clip / Most Popular Clips section. 有问题的站点在这里: http : //tlt.voltronik.co.uk-请向下滚动到“最新剪辑/最受欢迎的剪辑”部分。

There are a few videos that when hovered over, should play. 悬停时,应播放一些视频。 I've set the poster to be a relevant frame of the video so that they won't always use the first frame as it's not always the most appropriate. 我已将发布者设置为视频的相关帧,以使他们不会总是使用第一帧,因为它并不总是最合适的。 Here's the js i'm using for the play/pause on hover: 这是我用于悬停时播放/暂停的js:

var vid = document.getElementsByClassName("video-hover");

[].forEach.call(vid, function (item) {
  item.addEventListener('mouseover', hoverVideo, false);
  item.addEventListener('mouseout', hideVideo, false);
});

function hoverVideo(e) {   
  this.play();
}

function hideVideo(e) {
  this.pause();
}

The problem is (as you might have already discovered) is that sometimes the posters show and sometimes they don't. 问题是(正如您可能已经发现的),有时海报会显示,有时却不会。 Sometimes they all load without fail and sometimes none of them do. 有时它们全部加载都没有失败,有时却没有。 Most of the time however, when they do show, you hover over a video and nothing happens. 但是,大多数情况下,当它们确实显示时,您将鼠标悬停在视频上并没有任何反应。 You have to move the mouse cursor off of the video, then re-hover over the video for the video to play. 您必须将鼠标光标从视频上移开,然后将鼠标悬停在视频上才能播放视频。

I attempted to compensate for the posters not showing by setting a background image of the poster to sit behind the video but this doesn't seem to show properly either. 我试图通过将海报的背景图像设置在视频后面来补偿未显示的海报,但这似乎也无法正常显示。

I don't think it's anything to do with the rgba background or the parallax style video playing behind because this behaviour is also visible on the 'Timelapse Clips' page too. 我认为这与rgba背景或后面播放的视差样式视频无关,因为此行为在“ Timelapse Clips”页面上也可见。

Can anyone shed any light on why this might be happening? 谁能阐明为什么会这样吗?

Move the mp4 source tag above the webm. 将mp4来源标签移到webm上方。

The first time the video takes a moment to play because it has to load. 由于必须加载,因此视频第一次播放需要一点时间。 You could set preload="auto" to avoid this delay. 您可以设置preload =“ auto”以避免这种延迟。

I had the same problem you were having. 我遇到了同样的问题。 Though this doesn't address the poster issues, it achieves what I think you're hoping for. 尽管这不能解决发布者的问题,但可以实现我认为您希望的。 I had to remove the poster altogether and add an image with a display:none class that I add on hover with jQuery. 我必须完全删除海报,并添加带有display:none类的图像,该类在jQuery悬停时添加。 Here's my pen: http://codepen.io/rhenwilson/pen/zIcBC . 这是我的笔: http : //codepen.io/rhenwilson/pen/zIcBC

var figure = $("figure")
var vid = $("video");
var cover = $(".img-cover")
$(figure).hover(function()
       { $(cover).addClass("img-hide");
}, function()
        { $(cover).removeClass("img-hide");
}
);

[].forEach.call(vid, function (item) {
        item.addEventListener('mouseover', hoverVideo, false);
        item.addEventListener('mouseout', hideVideo, false);
});

function hoverVideo(e) {  
        this.play();
}

function hideVideo(e) {
        this.pause();
}

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

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