简体   繁体   English

在视频加载之前添加进度栏

[英]add progress-bar before video loading

How to add loader before video loading? 如何在视频加载之前添加加载器? I have used video-slider on my site also add pagepilling.js for video scroll. 我在网站上使用过video-slider,还添加了pagepilling.js进行视频滚动。 My video slider and video scroll with pagepilling.js working well dynamically. 我的视频滑块和带有pagepilling.js的视频滚动条可以动态良好地运行。

Now I want to add before video loading showing a video progress-bar and an image, after video loading playing the video and hide image and progress-bar. 现在,我想在视频加载之前添加,以显示视频进度条和图像,在视频加载之后播放视频并隐藏图像和进度条。 I have found a site using this, but I don't know how to do that? 我已经找到一个使用此工具的网站,但我不知道该怎么做? Please see the demo site and suggest me what I will do? 请访问演示站点,并建议我该怎么做? I have not used any code because my code is working well. 我没有使用任何代码,因为我的代码运行良好。 I need to add video-loading progress bar like the demo. 我需要添加视频加载进度条,如演示。 How can I do that? 我怎样才能做到这一点?

DEMO 演示

The HTML5 Media API includes events that you can listen for and react to that allows you do things like this. HTML5 Media API包含您可以监听和响应的事件,这些事件使您可以执行以下操作。 The API is here: API在这里:

It includes the following which are of interest in your case (from the above link): 其中包括您感兴趣的以下内容(来自上面的链接):

  • canplay: "Sent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the HAVE_ENOUGH_DATA readyState." canplay:“当有足够的可用数据可以播放媒体时发送,至少持续几帧。这与HAVE_ENOUGH_DATA readyState相对应。”
  • progress: "Sent periodically to inform interested parties of progress downloading the media. Information about the current amount of the media that has been downloaded is available in the media element's buffered attribute." 进度:“定期发送以通知感兴趣的各方有关媒体下载的进度。有关已下载媒体当前数量的信息,可在媒体元素的缓冲属性中找到。”

You can use these to achieve your requirement, for example, by: 您可以使用这些来满足您的要求,例如,通过:

  • on page load, initially show the image you want in place of the video along with a progress bar with the progress initially at zero. 在页面加载时,最初显示您想要的图像来代替视频,以及进度条,进度最初为零。
  • Add an event listener for the loading progress and update the progress bar when you get updates to this listener. 为加载进度添加事件侦听器,并在获取对该侦听器的更新时更新进度栏。
  • Add an event listener for the loading complete/canplay event and remove the progress bar and image, and show and play the video when this event fires. 为加载完成/可播放事件添加事件侦听器,并删除进度条和图像,并在事件触发时显示并播放视频。

As an example, you can listen for the canplay event like this: 例如,您可以侦听canplay事件,如下所示:

var yourVideo = document.getElementById("yourVideo");
yourVideo.oncanplay = function() {
    //Add your code here to remove the image,
    //remove the progress bar and
    //show and start the video
};

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

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