Last active
August 26, 2021 18:13
-
-
Save brettkelly/69501fa92fc47ebd7076386f9ddd4a78 to your computer and use it in GitHub Desktop.
Ad-hoc store/load playback position for embedded Vimeo players
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
/* | |
To Do: | |
1. Deal with multiple iframes. Don't just match the element type and assume it's a player. | |
2. Deal with multiple embedded players? | |
3. Handle a page close/reload event during playback | |
*/ | |
var iframe = document.querySelector("iframe"); | |
if (!iframe) { | |
console.log("No Vimeo player found"); | |
} else { | |
var player = new Vimeo.Player(iframe); | |
var videoId; | |
document.addEventListener("DOMContentLoaded", function () { | |
player.getVideoId().then(function (vid) { | |
videoId = vid; | |
var pp = window.localStorage.getItem(videoId); | |
if (pp) { | |
player | |
.setCurrentTime(pp) | |
.then(function (seconds) {}) | |
.catch(function (error) { | |
console.log(error); | |
}); | |
} | |
}); | |
}); | |
player.on("pause", function () { | |
player.getCurrentTime().then((time) => { | |
window.localStorage.setItem(videoId, time); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment