Different Ways to Play a Sound from a Web Page

Back to menu

7. Using a Java Applet

Java applets are not supported by every browser/platform, and unfortunately there are different versions of Java which make widespread compatibility quite difficult for high-quality audio. Java versions 1.0 and 1.1 are supported by the Microsoft Java Virtual Machine (Java VM) found in Internet Explorer. Later Java versions require a Plug-In to be installed. Mozilla requires the plug-in in any case.

Java 1.0/1.1 Applet

Here is a simple Java applet that you are welcome to use to replay audio through the Microsoft Java VM. The applet below displays a button which when pressed plays a sound. You can choose the button size and an image as shown. However in Java 1.0/1.1 the sound quality is limited to 8000 samples/sec μ-law encoded audio, which is rather poor for anything but speech. You can convert audio files to this format using SOX (sox inp.wav -r 8000 -U out.au).

    <applet code=AudioButton.class name=Audio1 width=40 height=40>
      <param name=image value="play.gif">
      <param name=audio value="success.au">
      <param name=bkgray value="128">
    </applet>
    

You'll also need to download the AudioButton.class file.

Compatibility: Internet Explorer, Firefox, Opera, Chrome.

Java 1.2 and later Applet

The same applet also runs under the Java 1.2 environment, but without the limitation on audio format. This means you can replay the full quality audio file. Java 1.2 is only supported through a plug-in. To install the latest version, go to http://java.sun.com/products/plugin/. This plug-in is required for Mozilla, Firefox or Opera.

    <applet code=AudioButton.class name=Audio1 width=40 height=40>
      <param name=image value="play.gif">
      <param name=audio value="success.wav">
      <param name=bkgray value="128">
    </applet>
    

You'll also need to download the AudioButton.class file.

Compatibility: Internet Explorer, Firefox, Opera, Chrome.

Next method ...