by Dinesh Thakur Category: AWT and Applets

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)

where,

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

Method

Description

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()

       {

             mysound.loop();

         }

     public void stop()

       {

             mysound.stop();

       }

The HTML code for SoundExample is

<HTML>

        <HEAD>

        </HEAD>

<BODY>

        <CENTER>

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

                 </APPLET>

        </CENTER>

</BODY>

</HTML>

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article