如何在html5视频上显示视图? [英] How to display views on html5 video?

查看:245
本文介绍了如何在html5视频上显示视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的HTML中获得一种类似于观看次数的YouTube。我希望每次观看者超过4分钟的视频时加1。

I am trying to get a sort of 'YouTube' like number of views section in my html. I want to add 1 everytime the viewer gets over minute 4 of the video.

到目前为止,我应用了这个Javascript,但它看起来不像工作,我错过了什么?

So far I applied this Javascript but it does not look like working, what am I missing?

<section id="totViews">
<script>

document.getElementById("totViews").innerHTML = counter;

    var counter = 0;

    $('section video').on("timeupdate", function() {
        if ($('section video')[0].currentTime >= 4) { counter++;
        }
    });

    </script> views
    </section>


推荐答案

JavaScript在用户的浏览器中运行。它无法与观看视频的其他浏览器通信,并且当您关闭页面时它将停止计数,因此它只能计算您在当前会话中观看视频的频率。

JavaScript runs in the user's browser. It has no way of communicating with other browsers viewing the video, and it will stop counting when you close the page, so it will only ever be able to count how often you watched the video in the current session.

如果你想让这项工作成功,你需要在你的服务器上加载和存储这些信息。

You need to load and store this information on your server somewhere if you want to make this work.

这篇关于如何在html5视频上显示视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆