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: have found this code which attempts to play an audio file called audio.mp3:
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:
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!
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
Para reproducir MP3 con java necesitamos una librera adicional. La ms bsica es JLayer. Nos bastar descargarla y aadir el jar jl1.0.1.jar al classpath de nuestro proyecto eclipse (o el ide que uses).
La clase Player tambin un mtodo play(int) en la que podemos indicar el nmero de tramas a reproducir. Player recuerda dnde iba reproduciendo y reproducir las n siguientes tramas que le indiquemos. Con este mtodo podemos hacer algo como esto para poder pausar la msica
En un hilo separado hemos lanzado un bucle infinito (while(true)) y dentro, si no estamos pausados (if (!pausa)), llamamos a player.play(1) para que reproduzca un frame de msica. Si este mtodo devuelve true, es que la trama se ha reproducido correctamente, si devuelve false, es que no hay ms tramas. As que si player.play(1) devuelve false, es que hemos llegado al final de la msica y terminamos el bucle infinito con break.
c80f0f1006