Embedding Sound in Web Pages, Part I: MIME Types - Doc JavaScript | WebReference

Embedding Sound in Web Pages, Part I: MIME Types - Doc JavaScript

MIME Types

Navigator 3.0x and 4.0x support the MimeType object (Internet Explorer 4.0x doesn't). A MimeType object can be an element of the navigator.mimeTypes array:


where index is either an integer or a string containing the desired MIME type. For example, you can reference the "audio/wav" MimeType object as follows:


A MimeType object can also be a property of a specific Plugin object:


where index is either an integer or a string containing the MIME type. For example, you can reference the "audio/wav" MimeType via the LiveAudio Plugin object as follows:


The following table summarizes the properties of a MimeType object:

Property Description
type The name of the MIME type.
description A description of the MIME type.
suffixes A string containing the MIME type's possible extensions. For example: "jpeg, jpg, jpe, jpv, vbs, jpegv".
enabledPlugin The Plugin object that can display data of the MIME type. enabledPlugin is null when there is no plug-in to display data of the specificied MIME type format.

The following example prints all MIME types supported by the browser. We extract the number of MIME types from the navigator.mimeTypes object's length property. The loop generates a table row for each MIME type:

document.write("<TABLE BORDER='1' CELLSPACING='0' CELLPADDING='3'>");
for (var i = 0; i < navigator.mimeTypes.length ; i++) {
  document.writeln("<TR VALIGN='top'><TD>", i, "</TD>",
  "<TD>", navigator.mimeTypes[i].type, "</TD>",
  "<TD>", navigator.mimeTypes[i].description, "</TD>",
  if (navigator.mimeTypes[i].suffixes != "")
    document.write(navigator.mimeTypes[i].suffixes + " * ");
  if (navigator.mimeTypes[i].enabledPlugin)

Here is a sample output generated by Navigator 3.0x or 4.0x:

0model/vrmlVRML Worlds wrl, wrzCosmo Player 1.0
1x-world/x-vrmlVRML Worlds wrl, wrz Cosmo Player 1.0
2audio/x-liveaudioStreaming Audio Metafiles lamNetscape Media Player
3audio/x-midiMIDI mid, midiLiveAudio
4audio/midiMIDI mid, midiLiveAudio
5audio/nspaudioNetscape Packetized Audiola, lmaLiveAudio
6audio/x-nspaudioNetscape Packetized Audiola, lmaLiveAudio
7video/msvideoVideo for Windows aviNPAVI32 Dynamic Link Library

Since Navigator cannot handle hundred line tables, we have restricted the printout to the first few MIME types (Navigator supports a few hundreds MIME types!). The script also prints a * character if the suffixes property is an empty string

It's important to understand the relationship between plug-ins (software modules) and MIME types. enabledPlugin is the plug-in configured for the specified MIME type. Each MIME type can be supported by multiple plug-ins, and each plug-in can handle multiple MIME types, but only one plug-in can be activated for a single MIME type. The enabledPlugin property is a reference to a Plugin object which represents the plug-in that handles the given MIME type.

Audio support on the Web is quite complicated. Navigator 3.0x and above can play embedded tracks provided that the LiveAudio plug-in is installed. Internet Explorer 4.0x and above can can play audio if the ActiveMovie Control is installed (it comes pre-packaged with Windows 95, but can also be downloaded for other platforms along with the browser). Note that many other plug-ins, for both browsers, support audio. However, since we are interested in JavaScript-enabled sound implementations, we will stick with the default LiveAudio plug-in (Navigator) and the Active Movie Control (Internet Explorer).

var NSsound =
  navigator.plugins && navigator.plugins["LiveAudio"] && navigator.javaEnabled();
var IEsound = navigator.plugins && document.all;
var audioEnabled = NSsound || IEsound;

We check if Navigator supports sound by verifying that plugins arrays exists and one of the supported plug-ins is "LiveAudio". On Explorer, it's enough to check that the platform is Windows 95 (plugins array exists), and the its version is 4.0x or above (document.all exists).


Created: May 31, 1998
Revised: May 31, 1998

URL: http://www.webreference.com/js/column20/mimetypes.html