Safari Reference Library Apple Developer
Search

Introduction

If you embed audio or video media in your website, you should read this document.

HTML5 is the next major version of HTML, the primary standard that determines how web content interacts with browsers. HTML5 enables audio and video to play natively in the browser without requiring proprietary plug-ins. With HTML5, you can add media to a website with just a few lines of code. You can also create customized media controllers for rich interactivity using standard web technologies.

The HTML5 <audio> and <video> tags make adding media to a website simple. Just use the src attribute to identify the media source and include a controls attribute so the user can play and pause the media.

Example:

<video src="http://Myserver.com/Path/Mymovie.mp4" controls> </video>

You can set additional attributes, such as autoplay or loop, optionally supply a height and width, or simply let the browser allocate the space it needs based on the media. In any case, it generally requires only a single line of code.

Safari on iPhone OS 3.0 and later (including iPad) and Safari on the desktop 3.1 and later (for Mac OS X and Windows) support the <video> and <audio> elements. Not all browsers support these tags yet, and not all types of encoded media play back in all browsers. However, there are simple ways to provide fallbacks if the browser doesn't yet support the <video> or <audio> tag, and simple methods to provide alternate media sources if the browser supports the tags but can't play a particular media file.

Because the <audio> and <video> elements are standard HTML they integrate automatically with CSS and JavaScript. You can combine CSS properties, JavaScript functions, and DOM events to create sophisticated movie controllers customized to your needs and aesthetics, yet entirely based on W3C standards and independent of third-party plug-in APIs.

Standard JavaScript methods allow you to play, pause, jump to a given point, or specify a new source, and DOM events notify you when the media loads, plays, pauses, or completes. You can apply CSS properties and use DOM events to modify <video> elements just as you would any other element—change the opacity, overlay text, move the element smoothly across the page, add a reflection, rotate the element in 3D, and so on. This document includes several examples.

Important: This is a preliminary document. Although it has been reviewed for technical accuracy, it is not final. Apple is supplying this information to help you adopt the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be vetted against final documentation. For information about updates to this and other developer documentation, you can check the ADC Reference Library Revision List. To receive notification of documentation updates, you can sign up for a free Apple Developer Connection Online membership and receive the bi-weekly ADC News e-mail newsletter. See http://developer.apple.com/products/for more details about ADC membership.)

Organization of This Document

This document shows you how to use the HTML5 <audio> and <video> tags in the following ways:

See Also




Last updated: 2010-03-18

Did this document help you? Yes It's good, but... Not helpful...