HTML5 Game - Using the source Element to Provide Multiple Audio Formats

Introduction

The following code shows how you can use the source element to provide multiple formats.

Demo

ResultView the demo in separate window

<!DOCTYPE HTML>  
<html>  
    <head>  
        <title>Example</title>  
    </head>  
    <body>  
        <audio controls autoplay>  
            <source src="http://java2s.com/style/demo/your.ogg" />  
            <source src="http://java2s.com/style/demo/your.mp3" />  
            <source src="http://java2s.com/style/demo/your.wav" />              
            Audio content cannot be played  
        </audio>  
    </body>  
</html>/*from   ww w  . jav  a2s  .  c  om*/

In the example above, I used the controls attribute so that the browser will display the default controls to the user.

Related Topic