-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Valik3201/vimeo-player
Vimeo player
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |