Skip to content

Commit

Permalink
Merge pull request #3 from Valik3201/vimeo-player
Browse files Browse the repository at this point in the history
Vimeo player
  • Loading branch information
Valik3201 authored Nov 14, 2023
2 parents 2d75e9b + e6aef3b commit 85b00a7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"url": "https://github.com/Valik3201/goit-js-hw-08/issues"
},
"dependencies": {
"@vimeo/player": "^2.20.1",
"lodash": "^4.17.21",
"modern-normalize": "^1.1.0",
"simplelightbox": "^2.14.2"
},
Expand Down
33 changes: 33 additions & 0 deletions src/js/02-video.js
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
// Added the @vimeo/player library as a project dependency via npm

// Import Vimeo Player and throttle
import Player from '@vimeo/player';
import throttle from 'lodash/throttle';

// Find the iframe element on page
const iframe = document.querySelector('iframe');

// Create an instance of Vimeo Player
const player = new Player(iframe);

// Define the key for local storage
const localStorageKey = 'videoplayer-current-time';

// Define the callback function for the timeupdate event
const onTimeUpdate = function (data) {
// Save the current time to local storage
localStorage.setItem(localStorageKey, data.seconds);
console.log('Current time saved to localStorage:', data.seconds);
};

// Add a throttled listener for the timeupdate event, limiting onTimeUpdate calls to every 1000 milliseconds.
player.on('timeupdate', throttle(onTimeUpdate, 1000));

// Set the current time using the saved value from localStorage
player
.setCurrentTime(JSON.parse(localStorage.getItem(localStorageKey)) || 0)
.then(function (seconds) {
console.log('Video resumed from saved time:', seconds);
})
.catch(function (error) {
console.error('Error setting current time:', error);
});

0 comments on commit 85b00a7

Please sign in to comment.