Monday, 26 September 2011

Java program to play an audio clip in Applet


/*<APPLET CODE="PlaySoundApplet" WIDTH="200" HEIGHT="300"></APPLET>*/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class PlaySoundApplet extends Applet implements ActionListener{
  Button play,stop;
  AudioClip audioClip;

  public void init(){
  this.setBackground(Color.blue);
  play = new Button("  Play in Loop  ");
  add(play);
  play.addActionListener(this);
  stop = new Button("  Stop  ");
  add(stop);
  stop.addActionListener(this);
  audioClip = getAudioClip(getCodeBase(), "mausam03(www.songs.pk).mp3");
  }

  public void actionPerformed(ActionEvent ae){
  Button source = (Button)ae.getSource();
  if (source.getLabel() == "  Play in Loop  "){
  audioClip.play();
  }
  else if(source.getLabel() == "  Stop  "){
  audioClip.stop();
  }
  }
}

Download this mp3 sound for play the above code:
Ik Tu Hi Tu Hi -Mausam

No comments:

Post a Comment