How to Work with AudioClip in Java?

audioclip in java
audioclip in java

How to Work with AudioClip in Java

Remember the issues with the plain audio class? If not then I recommend you to check this link quickly to find more on Audio.

To resolve the issues of audio, java came up with AudioClip class which solves the limitation of play() method.

The methods of AudioClip are defined below:

public AudioClip getAudioClip(URL url);//returns an audio clip object from the url. This method will not return
//until the audio clip has been loaded from the specified URL.So one should place it in a separate thread if
// the file is expected to take a while to download.
public AudioClip getAudioClip(URL url,String name);//Does the same but finds the audio file using base url and
// filename

AudioClip object provides the below methods:

public abstract void loop();//plays the clip in a continuous loop.
public abstract void play();//plays the clip from begining.
public abstract void stop();//stops the clip that is currently playing.

Here is an example how to work with AudioClips:

AudioClip tabla;
AudioClip flute;
Button startButton=new Button("Start");
Button conButton=new Button("Continue");
Button stopButton=new Button("Stop");
public void start(){
public void stop(){
public boolean action(Event e,Object button)
return true;

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *