Introduction
Introduction to HTML5 Video
- We wanted to have an external plug in like Flash to play the video on our page.
- There were no specific standard tags for playing the video.
HTML5 has introduced a new element <video>. Let us see how to use that element.
- <video width="500" controls>
- <source src="sibi.mp4" type="video/mp4">
- </video>
- <source src="mov_bbb.ogg" type="video/ogg">
- <!DOCTYPE html>
- <html>
- <title>HTML5 Video -Sibeesh Passion</title>
- <body>
- <div>
- <video width="500" controls>
- <source src=" sibi.mp4" type="video/mp4">
- It seems your browser is outdated one, be new yaar.
- </video>
- <div>
- <a href="Your video URL here">Your video URL here</a>.
- </div>
- </body>
- </html>
- The text “controls“ in the video markup is for adding the video player controls like play, pause and so on.
- The text “It seems your browser is an outdated one, be new yaar.” It will display only if your browser won't support HTML5.
- It is always good to set the width for the video element to avoid the flickering in the browser.
Adding your own controls (play, pause and so on)
You can also add your own controls like play and pause to the video element if you don't want to have the built-in control functionality.
Procedure:
- You must remove the text controls from the element first.
- Add the video tag.
It seems your browser is outdated one, be new yaar.
- <video id="video1" width="500">
- <source src="sibi.mp4" type="video/mp4">
- <source src="sibi.ogg" type="video/ogg">
- </video>
- Add UI elements
- <table>
- <tr>
- <td>
- <div onclick="playOrpause()">Play/Pause</div>
- </td>
- <td>
- <div onclick="big()">Big</div>
- </td>
- <td>
- <div onclick="small()">Small</div>
- </td>
- <td>
- <div onclick="normal()">Normal</div>
- </td>
- </tr>
- </table>
- Create the functions in the scripts.
- <script>
- var myVideo = document.getElementById("video1");
- function playOrpause() {
- if (myVideo.paused)
- myVideo.play();
- else
- myVideo.pause();
- }
- function big() {
- myVideo.width = 560;
- }
- function small() {
- myVideo.width = 320;
- }
- function normal() {
- myVideo.width = 420;
- }
- </script>
- <!DOCTYPE html>
- <html>
- <body>
- <script src="jquery-1.9.1.js"></script>
- <div>
- <table>
- <tr>
- <td>
- <div onclick="playOrpause()">Play/Pause</div>
- </td>
- <td>
- <div onclick="big()">Big</div>
- </td>
- <td>
- <div onclick="small()">Small</div>
- </td>
- <td>
- <div onclick="normal()">Normal</div>
- </td>
- </tr>
- </table>
- <br>
- <video id="video1" width="500">
- <source src="sibi.mp4" type="video/mp4">
- <source src="sibi.ogg" type="video/ogg">
- It seems your browser is outdated one, be new yaar.
- </video>
- </div>
- <script>
- var myVideo = document.getElementById("video1");
- function playOrpause() {
- if (myVideo.paused)
- myVideo.play();
- else
- myVideo.pause();
- }
- function big() {
- myVideo.width = 560;
- }
- function small() {
- myVideo.width = 320;
- }
- function normal() {
- myVideo.width = 420;
- }
- </script>
- </body>
- </html>
Wow, we have created our own controls.
Cool. That is all for today.
See you soon in the next part with another control. Please provide your valuable comments.
Kindest regards,
Sibeesh Venu.

Join the conversation! Your thoughts help the community grow.