I\'m having a weird problem. My two versions of chrome(regular & canary) refuse to loop the video i\'m showing. Or well, sometimes they loop it twice and stops after that. W
This happens only if you run your site locally...
And i had same problem with Chrome but i found solution in XAMP local server...
you can use any local server that you want(like wamp and etc)... but the site must be in server root directory... this way chrome understands that the video comes from server and not from local mashing
I have recently had some issue with this myself. It turned out to be something to do with my site being on localhost. When I move the site to my production server and tested remotely it all worked as expected.
To force it to work on localhost, I used the solution from Joakim Bananskal, but playing the video cause an error because it was already trying to play it, so I just had to reset the video first using load()
.
Having it set to loop also seemed to cause an issue, because the video never fired the ended
event.
My final solution for localhost is below:
$("video").each(function () {
this.loop = false;
this.onended = function () {
this.load();
};
this.play();
});
with this HTML:
<video preload="auto" autoplay>
<source src="/video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
<source src="/video.ogg" type="video/ogg">
<img src="/backupImage.png" />
</video>
I've also found that Chrome chokes if the MP4 keyframes aren't set properly. For example, in After Effects, in Output, if the key frame distance is left as "auto" the video doesn't loop properly.
My suspicion is that Chrome needs evenly divisible key frames within the length of the video, as in not ending between keyframes. i.e. if your video is 24 frames, make your key frame distance evenly divisible, 4 for example.
This one is solved, and here's the solution in my case:
The video had a resolution that was too big. Even if the bitrate was low, chrome didn't want to do it. Resized it to be 720p and it worked perfectly.
Other suggested solutions if you're having problems:
Set it to loop via javascript. This is also a good fallback for browsers not being okay with the loop attribute on the video tag (main example being ipad's). Below is some example code that I copied of a site yesterday (sorry, can't remember the source)
var myVideo = document.getElementById('video');
if (typeof myVideo.loop == 'boolean') { // loop supported
myVideo.loop = true;
} else { // loop property not supported
myVideo.on('ended', function () {
this.currentTime = 0;
this.play();
}, false);
}
myVideo.play();
For some reason I had issues with 'ended' event binding.
Here is how I fixed it:
added onended to invoke replay()
<video autoplay='true' onended="replay()"></video>
defined replay() as below:
function replay() { console.log('video ended'); document.getElementsByTagName('video').currentTime = 0; document.getElementsByTagName('video')[0].play(); }