Microreviews

Apple Google Microsoft Tablets Search Facebook

Audio and Video support in HTML 5 – the markup – Part 3

| 0 comments

This is the third and final part of the series of posts which cover audio and video support in HTML 5 (across various browsers).

HTML5_Badge_256

You can read the first part and the second part too. In this part we will cover the HTML 5 markup for the <video> element.  Going by basics all you need is:

  1. <video src="microreviews.webm"></video>

However, it is better to fix a height and width for the video

  1. <video src="microreviews.webm" width="320" height="240"></video>

If you don't want to create your own controls and wants the defaults to be used

  1. <video src="microreviews.webm" width="320" height="240" controls></video>

The preload attribute tells the browser that you would like it to start downloading (but not playing) the video file as soon as the page loads.

  1. <video src="microreviews.webm" width="320" height="240" preload></video>

  1. <video src="microreviews.webm" width="320" height="240" preload="none"></video>

The autoplay attribute  tells the browser that you would like it to start downloading the video file as soon as the page

loads, and you would like it to start playing the video automatically as soon as possible.

  1. <video src="microreviews.webm" width="320" height="240" autoplay></video>

However, as we have leant in the previous posts, all browsers don’t support all types of videos. So we need three video

files:

  1. <video width="320" height="240" controls>
  2. <source src="microreviews.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
  3. <source src="microreviews.webm" type='video/webm; codecs="vp8, vorbis"'>
  4. <source src="microreviews.ogv" type='video/ogg; codecs="theora, vorbis"'>
  5. </video>

As we can see that the video element doesn’t link to any video. Instead, it just specifies the height and the width of the

video and that default controls are needed. Each source element links to a single video file (with the src attribute),

and it also gives information about the video format (in the type attribute).

The type attribute is a combination of three pieces of information: the container format, the video codec, and the audio codec.

However, setting the type attribute in your HTML markup is not sufficient. You also need to ensure that your web server includes the proper MIME type in the Content-TypeHTTP header.

 

  1. AddType video/ogg .ogv
  2. AddType video/mp4 .mp4
  3. AddType video/webm .webm

If you’re using the Apache web server or some derivative of Apache, you can use an AddType directive in your site-widehttpd.conf or in an .htaccess file in the directory where you store your video files. (If you use some other web server, consult your server’s documentation on how to set the Content-TypeHTTP header for specific file types.)

If you want to get your videos to play everywhere without any problem, just use a copy of the codes from here.

Get in touch with the writer at mitra[dot]arkid[at]gmail[dot]com


Related posts:

  1. Audio and Video support in HTML 5 – audio codecs, h.264 licensing issues – Part 2
  2. Audio and Video support in HTML 5 – the basics-Part 1
  3. FluidHTML – Markup for Flash- What does it mean for HTML guys?
More in Tutorial (1 of 3 articles)