Hi, I am trying to play audio in a Java applet but it is not working. What could be the problem?
EDIT: Besides the limited number of files that Java can play, the problem was that I didn't realize that the bin folder (in Eclipse workspace) contains the .class file that is run. So my code referring to the getDocumentBase() couldn't find the audio file. -_-"
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Viewer extends Applet
implements MouseListener, MouseMotionListener {
AudioClip sound1;
AudioClip tap;
AudioClip clap;
public void init() {
sound1 = this.getAudioClip(getDocumentBase(),"boom.au");
tap = getAudioClip(getDocumentBase(), "tap.au");
clap = getAudioClip(getDocumentBase(), "clap.au");
this.resize(600,600);
addMouseListener(this);
setBackground(Color.BLACK);
}
public void paint (Graphics g) {
}
public void mouseClicked(MouseEvent e) {
sound1.play();
System.out.println("BOOM!");
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) {
tap.play();
System.out.println("tap!");
}
public void mouseReleased(MouseEvent e) { }
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) { }
}