Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- $(".video").on("click", function (ev) {
- addVimeoPlayer();
- });
- function addVimeoPlayer() {
- new Promise(function (resolve, reject) {
- setTimeout(function () {
- iframe = document.querySelectorAll('iframe');
- iframe = iframe[3];
- player = new Vimeo.Player(iframe);
- resolve(player);
- addVimeoPlayerEvent();
- exitBtnVimeoVideo();
- }, 1000);
- }).then(function (res) {
- console.log(res);
- });
- }
- function addVimeoPlayerEvent() {
- player.on('play', function (data) {
- jsonStatusVimeo(data, "play");
- });
- player.on('pause', function (data) {
- jsonStatusVimeo(data, "pause");
- });
- player.on('ended', function (data) {
- jsonStatusVimeo(data, "ended");
- });
- }
- function exitBtnVimeoVideo() {
- $(".lity-wrap").on("click", function (ev) {
- timeDuration = player.getDuration().then(function (duration) {
- return duration;
- }).catch(function (err) {
- console.log(err);
- });
- timeSeconds = player.getCurrentTime().then(function (seconds) {
- return seconds;
- }).catch(function (err) {
- console.log(err);
- });
- Promise.all([timeDuration, timeSeconds]).then(function (arr) {
- obj = {
- seconds: arr[1],
- percent: parseFloat((arr[1] / arr[0]).toFixed(3)),
- duration: arr[0]
- };
- jsonStatusVimeo(obj, "currentTime");
- player = undefined;
- }).catch(function (err) {
- console.log(err);
- });
- });
- }
- function jsonStatusVimeo(infoTimes, status) {
- Promise.all([player.getVideoTitle(), player.getVideoId()])
- .then(function (data) {
- infoTimes.percent = parseFloat((infoTimes.percent *= 100).toFixed(2));
- obj = {title: data[0], videoId: data[1], status: status, infoTimes: infoTimes};
- console.log(`name:${obj.title}, video:${obj.videoId}, status:${obj.status}: `);
- console.log(obj.infoTimes);
- //console.log(JSON.stringify(obj));
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement