Vimeo player time tracking using script

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

Answers:

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

});

Answer

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.