Thursday, June 27, 2013

Audio and Video in HTML5

<audio> and <video> tags of HTML5 allows us to incorporate native audio and video support without Flash.

To include audio and video we need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media.

The simplest way of embedding a video file in a webpage:

<video src="video.mp4" width="320" height="200" controls preload></video>

<audio src="audio.mp3" controls preload></audio>

We can use <source> tag to indicate media along with media type and many other attributes. A video/Audio element allows various source elements and browser will use the first recognized format:

<video width="618" height="347" controls preload> 
    <source src="video.mp4" media="only screen and (min-device-width: 568px)"></source>
    <source src="video.iphone.mp4" media="only screen and (max-device-width: 568px)"></source>

<audio controls preload> 
    <source src="audio.mp3"></source> 
    <source src="audio.ogg"></source> 

Attribute Specification:
Autoplay: The video/audio will automatically begin to play back as soon as it can do so without stopping to finish loading the data.
Autobuffer: The video/audio will automatically begin buffering even if it's not set to automatically play.
Controls: It will allow the user to control video/audio playback, including volume, seeking, and pause/resume playback.
Loop: It will allow video/audio automatically seek back to the start after reaching at the end.
Preload: This attribute specifies that the video/audio will be loaded at page load, and ready to run. Ignored if autoplay is present.
Src: The URL of the video/audio to embed.
Height: Height of the video's display area in pixels.
Width: Width of the video's display area in pixels.
Poster: URL of an image which will be displayed while the video is loading.


  1. This sample plug-in allows you to play back a game player's MP3 files at runtime. You can use this source plug-in if you want to give the game player the option to replace the game music with their own MP3 files. When using this plug-in, a game player's MP3 files can be sent through the Wwise pipeline at runtime and processed by the sound engine. This means you can take full advantage of all the features and effect processing in iomoio.