Created
November 21, 2014 18:12
-
-
Save giannif/60bec73704d8d37998f1 to your computer and use it in GitHub Desktop.
return the image object
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) { | |
// copy it because we're going to change the src | |
foundImage = _.clone(foundImage); | |
// get the number | |
var thumbnailNumber = Math.floor((time - foundImage.startTime) / foundImage.keyframeIntervalSeconds), | |
// get the padding | |
padding = Thumbnails.getTimeString(thumbnailNumber.toString().length); | |
// set the source | |
foundImage.src = foundImage.src.replace("{0:0000}", padding + thumbnailNumber); | |
} | |
// result | |
return foundImage; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment