-
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.
- Loading branch information
1 parent
af2cb04
commit 69f00de
Showing
2 changed files
with
23 additions
and
44 deletions.
There are no files selected for viewing
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,46 +1,18 @@ | ||
import Player from '@vimeo/player'; | ||
import throttle from 'lodash.throttle'; | ||
|
||
const KEY_STORAGE = 'videoplayer-current-time'; | ||
|
||
const iframe = document.querySelector('iframe'); | ||
iframe.style.margin = '20px auto'; | ||
iframe.style.display = 'flex'; | ||
|
||
const player = new Player(iframe); | ||
const throttle = require('lodash.throttle'); | ||
|
||
player.on('play', function () { | ||
console.log('played the video!'); | ||
}); | ||
|
||
player.getVideoTitle().then(function (title) { | ||
console.log('title:', title); | ||
}); | ||
player.on('timeupdate', throttle(updatingTimeLocalStorage, 1000)); | ||
|
||
player.on('timeupdate', throttle(updateingTimeLocalStorage, 1000)); | ||
|
||
function updateingTimeLocalStorage(data) { | ||
{ | ||
duration: 61.857; | ||
percent: 0.049; | ||
seconds: 3.034; | ||
} | ||
localStorage.setItem('videoplayer-current-time', data.seconds); | ||
// data is an object containing properties specific to that event | ||
function updatingTimeLocalStorage({ seconds }) { | ||
localStorage.setItem(KEY_STORAGE, seconds); | ||
} | ||
|
||
player | ||
.setCurrentTime(localStorage.getItem('videoplayer-current-time')) | ||
.then(function (seconds) { | ||
// seconds = the actual time that the player seeked to | ||
}) | ||
.catch(function (error) { | ||
switch (error.name) { | ||
case 'RangeError': | ||
// the time was less than 0 or greater than the video’s duration | ||
break; | ||
|
||
default: | ||
// some other error occurred | ||
break; | ||
} | ||
}); | ||
player.setCurrentTime(localStorage.getItem(KEY_STORAGE)); |
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