Audio and Video in HTML5

HTML5 has inbuilt support for both audio and video tags

This following code explains about embedding a video element.

Let’s examine the code now;

This sample example plays a video posted by quality point technologies in youtube.

Multiple file sources can be included in a single video tag using the tag <source>. They help us to provide video and audio in different formats in a different browser. For eg

If the browser supports Ogg but does not satisfy the codecs the video will not load. If the type attribute is specified then if the browser does not support the video/audio format then the query is not taken to the server to be processed and the parser will switch to next source code. If the type attribute is not specified in the tag then even if the browser does not support that video format that query is taken to the server an error is displayed.


Controlling media playback


Once the code has been included in the HTML element then these elements can be controlled as per our wish but within the allowed protocol using javascript.

This HTML element uses the play method to play the video on the web page.


Stopping the download of media


The code is very simple to pause the playing video as we have discussed how to start a video. But even if we pause the video the browser will continue to download the video and this trick can be used to stop the downloading video.


Seeking the media


Media can be played, stopped and even can be stopped to download and here is a sample code to seek through the media. This involves just seeking through the media using the time we have set in the HTML attribute.