Turn Desktop View Off
by Dinesh Thakur

The AudioClip class is used to load and play sound files. To load a sound file the getAudioClip () Method of the AudioClip class is used. The general form of the getAudioClip () method is


AudioClip getAudioClip (URL pathname, String filename)

AudioClip getAudioClip (URL pathname)


pathname is the address of the sound file. When the image file and the source file are in the same directory, getCodeBase () method is used as first parameter to the method.


filename is the name of the sound file

Some of the methods of AudioClip class along with their description are listed in Table



void play()

used to play the sound for once

void loop()

used to play the sound in loop

void stop ()

used to stop playing the sound

Example: An applet code to demonstrate the use of AudioClip class


import java.applet.*;

import java.awt.*;

public class SoundExample extends Applet


       private AudioClip mysound;

       public void init()


                 mysound=getAudioClip(getCodeBase(), "chimes.wav");


      public void start()




     public void stop()




The HTML code for SoundExample is






                <APPLETCODE="SoundExample.class" WIDTH="200" HEIGHT="l30">