I want to be able to make either a GUI or console application where the user clicks a button to select an audio file from their computer (of a compatible format) and it play
Here is a simple way to play a short clip.
import javax.sound.sampled.*;
import java.net.URL;
import javax.swing.JOptionPane;
class ClipTest {
public static void main(String[] args) throws Exception {
String clipName = null;
if (args.length==1) {
clipName = args[0];
} else {
clipName = "http://pscode.org/media/leftright.wav";
}
System.out.println("Looping '" + clipName + "'.");
URL url = new URL(clipName);
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
Clip clip = AudioSystem.getClip();
clip.open( ais );
clip.loop(2);
clip.start();
JOptionPane.showMessageDialog(null, "Close to end..");
}
}
F:\proj>java ClipTest http://pscode.org/media/100_2817-linear.wav
Looping 'http://pscode.org/media/100_2817-linear.wav'.
F:\proj>java ClipTest
Looping 'http://pscode.org/media/leftright.wav'.
F:\proj>