As it takes time for the video player to load the mp4 video, does HTML5 support playing a "loading" logo when loading the video ?
Since my asp.net apps is a mobile page, it needs the user to click on the video to play the video (android, iphone not support autoplay). So, I cannot make a "loading" logo as poster, otherwise, the user will be confused about it. I want to display a loading logo when user click play button on iPad.
thanks
Joe
There is a simple video attribute that allows the use of pre-loaded images. The "poster" attribute defines a poster image that is in place of the video. Show activity on this post. The poster attribute specifies an image to be shown while the video is downloading, or until the user hits the play button.
First, set up a loading image in a div. Next, get the div element. Then, set a function that edits the css to make the visibility to "hidden". Now, in the <body> , put the onload to the function name.
Basically we set the initial image source to the loader image. Once the image loads(load event triggered), we listen to it and set the image source to the actual image. 2. Now use the just need to use the created attributes on your images.
It took me a way too long to actually figure out how to do this, but I'm going to share it here because I FINALLY found a way! Which is ridiculous when you think about it, because loading is something that all videos have to do. You'd think they would have taken this into account when creating the html5 video standard.
My original theory that I thought should have worked (but wouldn't) was this
Simple, right? The problem was that I couldn't get the background image to show when the source elements were set, or the video.src attribute was set. The final stroke of genius/luck was to find out (through experimentation) that the background-image will not disappear if the poster is set to something. I'm using a fake poster image, but I imagine it would work as well with a transparent 1x1 image (but why worry about having another image). So this makes this probably a kind of hack, but it works and I don't have to add extra markup to my code, which means it will work across all my projects using html5 video.
HTML
<video controls="" poster="data:image/gif,AAAA"> <source src="yourvid.mp4" </video>
CSS (loading class applied to video with JS)
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 perfectly for me but only tested in chrome and safari on mac. Let me know if anyone finds bugs and or improvements!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With