Advertisement
Guest User

VimeoEvent

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.     $(".video").on("click", function (ev) {
  3.         addVimeoPlayer();
  4.     });
  5.  
  6.     function addVimeoPlayer() {
  7.         new Promise(function (resolve, reject) {
  8.             setTimeout(function () {
  9.                 iframe = document.querySelectorAll('iframe');
  10.                 iframe = iframe[3];
  11.                 player = new Vimeo.Player(iframe);
  12.                 resolve(player);
  13.                 addVimeoPlayerEvent();
  14.                 exitBtnVimeoVideo();
  15.             }, 1000);
  16.         }).then(function (res) {
  17.             console.log(res);
  18.         });
  19.     }
  20.  
  21.     function addVimeoPlayerEvent() {
  22.         player.on('play', function (data) {
  23.             jsonStatusVimeo(data, "play");
  24.         });
  25.  
  26.         player.on('pause', function (data) {
  27.             jsonStatusVimeo(data, "pause");
  28.         });
  29.  
  30.         player.on('ended', function (data) {
  31.             jsonStatusVimeo(data, "ended");
  32.         });
  33.     }
  34.  
  35.     function exitBtnVimeoVideo() {
  36.  
  37.         $(".lity-wrap").on("click", function (ev) {
  38.             timeDuration = player.getDuration().then(function (duration) {
  39.                 return duration;
  40.             }).catch(function (err) {
  41.                 console.log(err);
  42.             });
  43.  
  44.             timeSeconds = player.getCurrentTime().then(function (seconds) {
  45.                 return seconds;
  46.             }).catch(function (err) {
  47.                 console.log(err);
  48.             });
  49.  
  50.             Promise.all([timeDuration, timeSeconds]).then(function (arr) {
  51.                 obj = {
  52.                     seconds: arr[1],
  53.                     percent: parseFloat((arr[1] / arr[0]).toFixed(3)),
  54.                     duration: arr[0]
  55.                 };
  56.                 jsonStatusVimeo(obj, "currentTime");
  57.  
  58.                 player = undefined;
  59.             }).catch(function (err) {
  60.                 console.log(err);
  61.             });
  62.         });
  63.     }
  64.  
  65.     function jsonStatusVimeo(infoTimes, status) {
  66.         Promise.all([player.getVideoTitle(), player.getVideoId()])
  67.             .then(function (data) {
  68.                 infoTimes.percent = parseFloat((infoTimes.percent *= 100).toFixed(2));
  69.                 obj = {title: data[0], videoId: data[1], status: status, infoTimes: infoTimes};
  70.  
  71.                 console.log(`name:${obj.title}, video:${obj.videoId}, status:${obj.status}: `);
  72.                 console.log(obj.infoTimes);
  73.                 //console.log(JSON.stringify(obj));
  74.             });
  75.     }
  76. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement