简体   繁体   English

"删除 HTML5 视频上的黑色加载闪光"

[英]Remove black load flash on HTML5 video

I have been creating a website for an online game that I play.我一直在为我玩的在线游戏创建一个网站。 In the header I have a HTML5 video that plays very briefly (1second).在标题中,我有一个播放非常短暂(1 秒)的 HTML5 视频。 In Internet Explorer there is no issue, however in Chrome as the video is loading there is a very brief flash of black screen.在 Internet Explorer 中没有问题,但在 Chrome 中加载视频时会出现非常短暂的黑屏闪烁。 Is there any way that I can remove this flash, or, failing that, make it white to match the background?有什么办法可以去掉这个闪光灯,或者如果做不到,让它变成白色以匹配背景? You can see what I mean here http://testingfortagpro.meximas.com/ .你可以在这里看到我的意思http://testingfortagpro.meximas.com/ If you try it in IE and the Chrome you will see the difference in how the video loads.如果您在 IE 和 Chrome 中尝试它,您将看到视频加载方式的不同。 Alternatively is there any better way of implementing this?或者有没有更好的方法来实现这个? I have tried using a animated GIF however quality is significantly reduced.我曾尝试使用动画 GIF,但质量显着降低。

Thanks!谢谢!

The Poster section of this blog post indicates the following: 博文的海报部分显示以下内容:

"If you do not specify a poster image the browser may just display a black box filling the dimensions of the element." “如果你没有指定海报图像,浏览器可能只显示填充元素尺寸的黑盒子。”

So you can't seem to fix this by simply adding a background-color of white to the video element... but you can add a simple white poster image like so: 所以你似乎无法通过简单地在video元素中添加白色的背景颜色来解决这个问题......但是你可以添加一个简单的白色海报图像,如下所示:

 <video width="320" height="240" autoplay="" poster="http://dummyimage.com/320x240/ffffff/fff" > <source src="http://testingfortagpro.meximas.com/movie2.mp4" type="video/mp4"> </video> 

You can use transparent gif poster: 你可以使用透明的gif海报:

poster="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

But that wasn't enough to eliminate blinking in Firefox. 但这还不足以消除Firefox中的眨眼。 I ended up by hiding the video until it's playing: 我最后隐藏了视频直到它正在播放:

<video autoplay style="visibility:hidden;" onplay="var s=this;setTimeout(function(){s.style.visibility='visible';},100);">

Adjust the timeout as you see fit. 根据需要调整超时。 When not using autoplay, I had to increase it up to 400 ms. 不使用自动播放时,我不得不将其增加到400毫秒。

I had the same problem and fixed it by hiding the video element using CSS display:none until the video element signalled it had finished loading via its onLoadedData event, and in response to that event I set display:block. 我遇到了同样的问题并通过使用CSS display:none隐藏视频元素来修复它,直到视频元素通过其onLoadedData事件发出信号已完成加载,并且为了响应该事件我设置了display:block。

That got rid of the black flash. 那摆脱了黑色闪光。

Putting in a poster attribute in the video tag did not stop the black box from flashing when the user refreshes the page however I used the hide function on the 'beforeunload' event and now the black flash is gone. 当用户刷新页面时,在视频标签中放置海报属性并不会阻止黑盒子闪烁,但是我在'beforeunload'事件中使用了隐藏功能,现在黑色闪光灯消失了。

$(window).on('beforeunload', function() {
   $("video").hide();
});

I had the same blinking problem in Firefox, even with a poster attribute set. 即使设置了海报属性,我在Firefox中也有同样的闪烁问题。 I fixed this by adding a background-image to the video tag that corresponded to the first frame of my video. 我通过在视频标记中添加背景图像来修复此问题,该视频标记对应于我视频的第一帧。

$(window).on('beforeunload', function() { $("video").hide(); }); $(window).on('beforeunload',function(){$(“video”)。hide();});

This will hide the video element just before the window unloads and loads the next document. 这将在窗口卸载并加载下一个文档之前隐藏视频元素。

I got rid of the flashing black box by adding style="background-color:white;"我通过添加 style="background-color:white;" 摆脱了闪烁的黑框to the video element.到视频元素。

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

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