It took me too much time to actually figure out how to do this, but I'm going to share it here because I FINALLY found a way! Which is funny when you think about it, because downloading is what all the videos need to do. You would think that they would take this into account when creating the html5 video standard.
My initial theory, which I thought about, was to work (but was not), was
- Add upload bg image to video when uploading via js and css
- Delete when ready to play.
Simple, right? The problem was that I could not get the background image to show when the original elements were set or the video.src attribute was set. The last stroke of genius / good luck was to find out (through experiments) that the background image would not disappear if the poster was set up for something. I am using a fake poster image, but I think this will work with a 1x1 transparent image as well (but why bother with another image). Thus, this makes it probably a kind of hack, but it works, and I donโt need to add extra markup to my code, which means that it will work in all my projects using html5 video.
HTML
<video controls="" poster="data:image/gif,AAAA"> <source src="yourvid.mp4" </video>
CSS (loading class applied to JS videos)
video.loading { background: black url(/images/loader.gif) center center no-repeat; }
Js
$('#video_id').on('loadstart', function (event) { $(this).addClass('loading'); }); $('#video_id').on('canplay', function (event) { $(this).removeClass('loading'); $(this).attr('poster', ''); });
This works fine for me, but it only checks on Chrome and Mac Safari. Let me know if anyone finds bugs and improvements!
pixelearth
source share