Javascript - 在视频直播结束前隐藏 div 1 秒
Javascript - hide div 1 sec before live stream on video ends
我在页面中有这个:
<video src="blob://some-live-stream" autoplay></video>
<div id="hideMePlease"> hide 1 sec before video ends</div>
我想在视频结束前隐藏 div 1 秒,我该怎么做?
N.B:我不知道视频时长,是直播,视频自动停止,我自己没办法停止。
如果像您所说的那样,您无法知道视频的长度,因为它是流式传输,那么您不可能(尽管有相对论时间旅行)安排一个活动秒才结束。
但是,我至少会先 尝试 使用视频的持续时间 属性,元数据可能会尽早作为流的一部分提供在。如果是,您可以使用它来安排 div
.
的隐藏
As an aside, if you visit the page http://www.w3.org/2010/05/video/mediaevents.html, you'll find that the duration is set correctly as soon as you start playing the video, despite the fact it seems to be streaming from either an MP4, OGG or WEBM file). So it's at least possible, though it may depend on the data stream itself (whether the metadata comes before or after the actual video data).
如果数据 不 可用(我认为在这种情况下你会得到 Inf
持续时间),那么你只需要隐藏div
之后尽早。
大概是在它完成时(触发 onended
事件)。
因此,简而言之,如果您可以获取 持续时间(或定期获取剩余时间可能更好),请使用它。否则退回到最后隐藏它并开始麻烦 w3c 以在 HTML6.
中提供您想要的功能
我在页面中有这个:
<video src="blob://some-live-stream" autoplay></video>
<div id="hideMePlease"> hide 1 sec before video ends</div>
我想在视频结束前隐藏 div 1 秒,我该怎么做?
N.B:我不知道视频时长,是直播,视频自动停止,我自己没办法停止。
如果像您所说的那样,您无法知道视频的长度,因为它是流式传输,那么您不可能(尽管有相对论时间旅行)安排一个活动秒才结束。
但是,我至少会先 尝试 使用视频的持续时间 属性,元数据可能会尽早作为流的一部分提供在。如果是,您可以使用它来安排 div
.
As an aside, if you visit the page http://www.w3.org/2010/05/video/mediaevents.html, you'll find that the duration is set correctly as soon as you start playing the video, despite the fact it seems to be streaming from either an MP4, OGG or WEBM file). So it's at least possible, though it may depend on the data stream itself (whether the metadata comes before or after the actual video data).
如果数据 不 可用(我认为在这种情况下你会得到 Inf
持续时间),那么你只需要隐藏div
之后尽早。
大概是在它完成时(触发 onended
事件)。
因此,简而言之,如果您可以获取 持续时间(或定期获取剩余时间可能更好),请使用它。否则退回到最后隐藏它并开始麻烦 w3c 以在 HTML6.
中提供您想要的功能