Learning Resources
HTML5 Audio and Video
HTML5 introduces built-in media support via the
Embedding media
Embedding media in your HTML document is trivial:
The srcattribute can be a URL of the audio file or the path to the file on the local system.
This code example uses attributes of the
- controls : Displays the standard HTML5 controls for the audio on the web page.
- autoplay : Makes the audio play automatically.
- loop : Make the audio repeat (loop) automatically.
The preloadattribute is used in the audio element for buffering large files. It can take one of 3 values:
- "none" does not buffer the file
- "auto" buffers the media file
- "metadata" buffers only the metadata for the file
Multiple source files can be specified using the
1
2
3
4
5
|
<
|
This plays the Ogg file in browsers supporting the Ogg format. If the browser doesn't support Ogg, the browser uses the MPEG-4 file. See also the list of media formats supported by the audio and video elements in different browsers.
You may also specify which codecs the media file requires; this allows the browser to make even more intelligent decisions:
1
2
3
4
|
<
|