使用脚本的Vimeo播放器时间跟踪 [英] Vimeo player time tracking using script

查看:151
本文介绍了使用脚本的Vimeo播放器时间跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Vimeo服务器检索视频以在我的网站上播放课程视频.单击标签im即可在弹出窗口中播放视频.

I am retrieving videos from Vimeo server to play course videos in my website. On click of tag im playing the video in popup.

<a class="btn btn-primary btn-lg popup-vimeo btn-video" href="<?php echo 'https://player.vimeo.com/video/' . $vdoid; ?>">
   <i class="fa fa-play" aria-hidden="true" style="font-weight:600;" id="<?php echo "vdo_" . $vv; ?>"></i></a>

现在,我想使用脚本来跟踪视频的当前时间.但是单击该标签后,它将弹出一个单独的视图页面(在检查时).

Now I want to track the video current time using script. But on click of that tag it loads a separate view page(while inspecting) as popup.

我尝试跟踪播放器并从播放器获取当前播放时间,并且尝试使用此脚本.

I tried to track the player and to get the current played time from the player and i tried using this script.

<script src="https://player.vimeo.com/api/player.js"></script>

<script>
$(document).on('click', '.btn-video', function ()
{
    var id = $(this).attr("id");
    var iframe = document.getElementById(id);
    var vPlayer = new Vimeo.Player(iframe);

    setInterval(function ()
    {
        console.log(iframe);
        console.log(vPlayer);
        var currtym = vPlayer.getCurrentTime();
        console.log(currtym);
        var currentTime = vPlayer.currentTime;
        console.log(currentTime);
    }, 1000);
});

但是我的想法已经用完了.有人请帮我弄清楚!! 谢谢...

But im running out of ideas. Someone please help me to figure it out.!! Thanks...

推荐答案

我发现了另一个更好的解决方案,用于检索endTime,以及视频进度百分比.可能会帮助某人...

I found another better solution to retrive endTime, video progress percent as well. Might help someone...

var vdo_play = "";
$(document).on('click', '.btn-video', function ()
{
    if (vdo_play)
    {
        clearInterval(vdo_play);
    }
    var player = new Vimeo.Player($(".mfp-iframe")[0]);
    var currentPos, percentage, vdoEndTym = "";
    vdo_play = setInterval(function ()
    {
        player.on('timeupdate', function (getAll)
        {
            currentPos = getAll.seconds; //get currentime
            vdoEndTym = getAll.duration; //get video duration
            percentage = (getAll.percent * 100)+"%";
            console.log('currentPos: ' + currentPos);
            console.log('percentage: ' + percentage);
        });
        player.on('ended', function ()
        {
            clearInterval(vdo_play);
        });
    }, 1000);
});

这篇关于使用脚本的Vimeo播放器时间跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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