Skip to content

Instantly share code, notes, and snippets.

@jwhitehorn
Last active Oct 21, 2020
Embed
What would you like to do?
<html>
<head>
</head>
<body>
<video width="960" height="540" controls>
<source src="" type="video/mp4">
</video>
<script type="application/javascript">
function loadPlayer() {
var urlParams = new URLSearchParams(window.location.search);
var video = document.getElementsByTagName("video")[0];
video.src = urlParams.get("src");
video.onloadeddata = function(){
var offsetStr = urlParams.get("offset");
if(offsetStr && offsetStr.indexOf(":") > 0){
var offsetParts = offsetStr.split(":");
var frame = parseInt(offsetParts[0]);
var totalFrames = parseInt(offsetParts[1]);
var percentage = frame / totalFrames;
var targetOffsetInSeconds = video.duration * percentage;
video.currentTime = parseInt(targetOffsetInSeconds);
}
}
}
setTimeout( loadPlayer, 0);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment