0

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

Venky
  • 31
  • 1
  • 5

2 Answers2

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

});

  • Your code doesn't work. You are calling the VPlayer object, and then later simply a player object. Which one is it? Even when I correct those errors, the console.log(currentTime) only shows the value '0' as was set above – Mike Szostech Jun 10 '20 at 17:23
0

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);
});
Venky
  • 31
  • 1
  • 5