HTML5 Game - Support more format via video element using source element

Introduction

You use the source element to specify multiple formats.

This element is described in the following table.

Element:source
Element Type: N/A
Permitted Parents:video, audio
Local Attributes: src, type, media
Contents: None
Tag Style: Void element
Style ConventionNone

The following code shows how you can use the source element to provide the browser with a choice of video formats.

Demo

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>

<head>
    <title>Example</title>
</head>/*  w  ww .  j av  a 2s .  c o m*/

<body>
    <video controls width="360" height="240">
        <source src="http://java2s.com/style/demo/your.webm" />
        <source src="http://java2s.com/style/demo/your.ogv" />
        <source src="http://java2s.com/style/demo/your.mp4" />
        Video cannot be displayed
    </video>
</body>

</html>

The browser tries to work down the list in sequence looking for a video file it can play.

The browser may uses multiple requests to get additional information about each file.

Related Topic