html5 video tag Complete Guide

Basically in this tutorial we are explaining all kind of thing about html5 video tag.
I came up with this idea and it works perfectly for me so i thought i share with you may be it will help of you.
So basically we want to get tour of the HTML5 video tag how to resize poster to the videos actual size. Here i am writing some examples of HTML5 video tag.

HTML5 video hide controls until hover

Here i am showing video player controls on mouse hover and hide on mouse leave see below example.

// HTML Code
<video width="100%" height="100%" id="VideoId">
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
jQuery('#VideoId').hover(function toggleControls() {
    this.setAttribute("controls", "controls");
});
jQuery('#VideoId').mouseout(function(){
    this.removeAttribute("controls")
});
</script>

How to add video thumbnail in html5 video tag

Yes here is a way to set thumbnail image on HTML5 video if you want to see some pictures before play then you should follow the below example and code.
Add poster=”videothumbnail.png” to the video tag.

<video width="100%" height="100%" poster="videothumbnail.png" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

How to set HTML5 video tag thumbnail with 100% width

You can use simply set preload=”none” attribute to make VIDEO background visible. And you can use background-size: cover below is a example.

// HTML Code
<video width="100%" height="100%" poster="videothumbnail.png" preload="none" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// CSS Code
<style>
#VideoId {
    background: transparent url('videothumbnail.png') 50% 50% / cover no-repeat ;
}
</style>

Without adding controls how to play video of html5 video tag

Here i am showing example for how can we play video without adding controls attribute in video tag using couple of lines JavaScript code.

// HTML Code
<video width="470" height="255" poster="placeholder.png" onclick="this.play()" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
    <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
var VideoId = document.getElementById('VideoId');
function videoPausePlayHandler(e) {
    if (e.type == 'playing') {
        //add controls
        VideoId.setAttribute("controls","controls");
    } else if (e.type == 'pause') {
        //remove controls
        VideoId.removeAttribute("controls");
    }
}
//Add event listeners
VideoId.addEventListener('playing', videoPausePlayHandler, false);
VideoId.addEventListener('pause', videoPausePlayHandler, false);
</script>

IF YOU LIKE THIS TUTORIAL DON’T FORGET SHARE WITH YOUR FRIENDS!

Leave a Reply

Related Posts: You may like

Get Latitude Longitude from Address

cookie policy popup

How to make a sticky sidebar on scroll

How to get the value of HTML tag using JS

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.