1

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!

bob sam
  • 35
  • 2
  • 6

3 Answers3

0

try to introduce the library (jl1.0.1.jar) straight in your project , right click on your project -> properties -> Java Build Path -> Libraries -> Add External Jar then Ok , Clean project and run again

0

Re write the first line of your code from -

import javazoom.jl.*; 

TO 

import javazoom.jl.player.Player;

This should solve the compilation problem

0

Your project should be a Maven project.

1, download this jar file from here https://jar-download.com/artifacts/javazoom/jlayer/1.0.1/source-code

2,click your project title, -> new -> directory -> create a folder called lib -> move the jar file you download to lib folder

3, need to configure it as a dependency: click the jar file -> new-> add as a library, then it becomes your part of your project.