Embedding QuickTime in HTML

Every once in a while, a developer new to QuickTime will post to one of the developer lists, saying he needs QTJ to put a QuickTime movie in a web page.

QTJ is great, but this is way, way overkill. For this task, you don’t need QTJ. In fact, you’d just be creating headaches for yourself by requiring QTJ and dealing with the hassles of applets. Instead, you can just embed QuickTime content in HTML.

Note

The mailing lists at http://lists.apple.com/ are a great source of information, particularly quicktime-java, quicktime-users (authoring), and quicktime-api (native programming). java-dev is also helpful for figuring out issues with Mac OS X’s Java implementation.

How do I do that?

In your HTML page, use an <object> tag, which wraps an <embed>, as shown in Example 1-1.

Example 1-1. Embedding QuickTime in HTML

<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
 width="160" height="136"
 codebase="http://www.apple.com/qtactivex/qtplugin.cab">
   <param name="src" VALUE="buhbuhbuh.mov"/>
   <param name="autoplay" VALUE="true"/>
   <param name="loop" VALUE="true"/>
   <param name="controller" value="true"/>
<embed src="buhbuhbuh.mov" width="160" height="136"
  scale="tofit"
  controller="true"
  autoplay="true"
  loop="true"
  pluginspage="http://www.apple.com/quicktime/download/"/>
</object>

The parameters are generally self-explanatory: height, width, and src are the only ones that are actually required. Because I’ve chosen to include a controller widget, I add 16 to the height parameter and use the scale parameter with the value tofit.

A web page using this tag is shown in Figure 1-4.

Embedding QuickTime movie in HTML

Figure 1-4. Embedding QuickTime movie in HTML

What just happened?

The weird thing about this is, of course, the tag-within-a-tag arrangement. We do this because although most browsers use the <embed> tag to use plug-ins, Internet Explorer on Windows is special and insists that we use an <object> tag to talk to a QuickTime ActiveX control.

Because of this arrangement, you have to list all the parameters twice, once in each tag. In the <embed> tag they’re attributes, and in the <object> tag they’re child <param> elements. Each tag also has some boilerplate code, such as the <embed>’s pluginspage and the <object>’s classid and codebase.

What about...

...other options for the plug-in? There are too many to cover here. Check out http://www.apple.com/quicktime/authoring/embed.html. There’s also some support for controlling a movie via JavaScript in some browsers (including IE and Mozilla derivatives, but not Safari as of this writing), using the attribute enablejavascript.

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.