Simple audio, video and Flash uses in HTML 5

Many web browsers introduced support for the HTML 5 audio and video elements, providing the easy way to add media into HTML pages.  At the moment, Ogg Theora or Theora, Ogg Vorbis or Vorbis, and WAV format media is supported.

Vorbis is an audio format specification and codec for lossy audio compression. Vorbis is free and mostly used in conjunction with the Ogg format and it is therefore often known as Ogg Vorbis.
Filename extension: .ogg .oga
Internet media type: audio/ogg, audio/vorbis, audio/vorbis-config

Theora is a free and open lossy video compression codec. It includes the Vorbis audio codec and the Ogg container.
Filename extension: .ogv
Internet media type: video/ogg

Adding Media with HTML 5

Adding media in your HTML document is very easy. This example plays a Ogg video from HTML5Samples website.

<video src="http://html5samples.com/Files/video_test.ogg" controls>
  Your browser does not support the <code>video</code> element.
</video>

Multiple source files can be given using the source element in order to provide video/audio encoded in different formats for different browsers. For example:

<video controls>
  <source src="video_test.ogg" type="video/ogg">
  <source src="video_test.mp4">
  Your browser does not support the <code>video</code> element.
</video>

will by play the Ogg video file in browsers supporting the Ogg format. If the browser couldnt play Ogg file, it should try to use the MPEG-4 file.

You also can define which codecs the media file must uses; this example lets the browser to make even more smart decisions:

<video controls>
  <source src="video_test.ogg" type="video/ogg; codecs=&quot;dirac, speex&quot;">
  Your browser does not support the <code>video</code> element.
</video>

Here, we define that the video must uses the Dirac and Speex codecs. If the browser only supports Ogg, but not Dirac and Speex codecs, the video will not be loaded.

If type isn’t specified, the media’s type is retrieved from the server and checked to see if Gecko can handle it; if it can’t be rendered, the next source is checked.  If none of the specified source elements can be used, an error event is dispatched to the video element.  If type is specified, it’s compared against the types Gecko can play, and if it’s not recognized, the server doesn’t even get queried; instead, the next source is checked at once.

Using Flash

You could use object element to play a Flash format movie if the HTML 5 video element doesn’t work:

<video src="video_test.ogv" controls>
    <object data="video_test.swf" type="application/x-shockwave-flash">
      <param value="video_test.swf" name="movie"/>
    </object>
</video>

You shouldn’t embed classid in the object tag if you want it to be compatible with browsers other than Internet Explorer.

Incoming search terms:

  • html5samples com/files/video_test ogg
  • simple html code audio
Share
, , , , ,

23 Comments

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
19 visitors online now
7 guests, 12 bots, 0 members
Max visitors today: 23 at 04:00 pm UTC
This month: 63 at 02-01-2012 04:28 pm UTC
This year: 63 at 02-01-2012 04:28 pm UTC
All time: 122 at 03-21-2010 01:46 pm UTC