I am trying to use an API by JZoom called JLayer which allows one to play audio files among other things. I downloaded the JLayer 1.0.1 version. Here is the link to their website: http://www.javazoom.net/javalayer/sources.html.I have found this code which attempts to play an audio file called audio.mp3
:
import javazoom.jl.*;
import java.io.FileInputStream;
public class Sound {
public static void main(String arg[]) {
try {
FileInputStream file = new FileInputStream("C:\\Users\\Sam\\Desktop\\dreamBeatsWorkspace\\dreamBeats\\audio.mp3");
Player playMP3 = new Player(file);
playMP3.play();
} catch (Exception e) {
}
}
}
When I write this in Eclipse it underlines the Player
part of Player playMP3 = new Player(file);
and asks for a Player class. I assume this means that the Player class is not defined. On the other hand I have tried to download and implement the JLayer library by going to Window->Preferences->Java->Build Path->User Libraries
. Then I created a new folder called audio lib
and went to Add External JARS...
from their I chose the files jl1.0.1
in C:\Users\Sam\Desktop\jlayer1.0.1\JLayer1.0.1
, Player.class
in C:\Users\Sam\Desktop\jlayer1.0.1\JLayer1.0.1\classes\javazoom\jl\player
and Player.java
in C:\Users\Sam\Desktop\jlayer1.0.1\JLayer1.0.1\src\javazoom\jl\player
then hit open for all of them and finally I hit OK. I proceed to write my code in a new class I created called Sound. Finally when I ran this code this error message popped up in the console:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Player cannot be resolved to a type
Player cannot be resolved to a type
at Sound.main(Sound.java:9)
I am assuming I need to find a way to make a class path to where the Player class is defined. I don't know how to do this and Ideas on how to build a class path to the location of the Player class in the Eclipse software would be very helpful. All ideas on what went wrong and how one can play an audio file with the JLayer library would be much appreciated. Thank you for your help!