Vimeo player time tracking using script

别说谁变了你拦得住时间么 提交于 2019-12-11 18:12:30

问题


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...


回答1:


<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 = 0;
    player.getCurrentTime().then(function(currentTime) {});        
    console.log(currentTime);
}, 1000);

});




回答2:


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);
});


来源:https://stackoverflow.com/questions/54398715/vimeo-player-time-tracking-using-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!