Created
April 7, 2017 00:00
-
-
Save ayamflow/d91f7100feeaa4093f2883f5c8fa1f83 to your computer and use it in GitHub Desktop.
Force play video
This file contains hidden or 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
// https://github.com/hay/gifvideo/blob/master/gifvideo.js | |
var start; | |
var previousTime; | |
video.load(); | |
// requestAnimationFrame automatically provides Date.now() | |
function play(now) { | |
// only play if it has the data, | |
// without waiting for ambiguous events | |
if (video.readyState >= video.HAVE_FUTURE_DATA) { | |
if (video.currentTime >= video.duration - 0.05) { | |
// safer way to check whether the video is ended | |
video.currentTime = 0; // restart video | |
} else { | |
//make it start at 0 | |
previousTime = previousTime || now; | |
// increase it by the time it passed since the last | |
// animationFrame | |
video.currentTime += (now - previousTime) / 1000; | |
} | |
} | |
previousTime = now; | |
requestAnimationFrame(play); | |
} | |
play(Date.now()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment