I put together this applet to play sound but for some reason the sound is not playing. It's probably something simple, but what am I doing wrong here? I added the sound to the right location, and I am not getting any errors, but I am not getting anything working.
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
public class MediaPlayer extends Applet implements ActionListener{
Button playBtn;
Button pauseBtn;
Button loopBtn;
URL soundPath;
AudioClip sound;
public void init() {
playBtn = new Button("Play");
add(playBtn);
playBtn.addActionListener(this);
pauseBtn = new Button("Pause");
add(pauseBtn);
pauseBtn.addActionListener(this);
loopBtn = new Button("Loop");
add(loopBtn);
loopBtn.addActionListener(this);
try{
soundPath = new URL(getCodeBase(),"office.wav");
}catch(Exception e){
System.out.print(e.toString());
}
sound = Applet.newAudioClip(soundPath);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == playBtn) sound.play();
if(e.getSource() == pauseBtn) sound.stop();
if(e.getSource() == loopBtn) sound.loop();
}
}