I have made a GUI which is pretty simple, looking similar to this:
Where I simply do
- Open to browse a music file
- Play to play the music
- Stop to stop the music
Now I came to a problem where I don't really know how to make it, so my program understands the audio. However I started with this:
if (e.getSource() == btnOpen) {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
//This is where a real application would open the file.
System.out.println("File: " + file.getName() + ".");
} else {
System.out.println("Open command cancelled by user.");
}
System.out.println(returnVal);
}
Which opens the browser and lets me choose a file. The only problem now is that I don't really know and haven't found on Google how to setup as an audio file. So basically what I want is like in the picture. When I open an MP3 file, it should show text of what it's called (But it's simple, just to edit the Jlabel which I can make later on) and the Play and stop.
The main problem now is how to make so whenever I choose an audio file (mp3) it should understand it and when pressing Play, it should play the song. but I have not found any solutions on Google so this is what I need help with.
Edit: So I luckliy with adding JAR and so on got mp3 to work but now to Wav. Since I haven't found anywhere how to have both Wav and Mp3 and make it work as a player. So my question is, How could I make it work?