Last active
August 29, 2015 14:10
-
-
Save giannif/63c3e124e826d3e22b0a to your computer and use it in GitHub Desktop.
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
/* global _ */ | |
var Thumbnails = { | |
// util to get the number of 0s | |
getTimeString: function(chars) { | |
var s = ""; | |
_.times(4 - chars, function() { | |
s += "0"; | |
}); | |
return s; | |
}, | |
// pass in the mediaGen.image and the current time of the video | |
getThumbnail: function(images, time) { | |
// we want the lowest time, e.g. 29.9 = 29 | |
time = Math.floor(time); | |
// find the image that is in the range | |
var foundImage = _.find(images, function(image) { | |
return time >= image.startTime && time < image.endTime; | |
}); | |
if (foundImage) { | |
// get the number | |
var thumbnailNumber = Math.floor((time - foundImage.startTime) / foundImage.keyframeIntervalSeconds), | |
// get the padding | |
padding = Thumbnails.getTimeString(thumbnailNumber.toString().length); | |
// return the src | |
return foundImage.src.replace("{0:0000}", padding + thumbnailNumber); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment