how to put audio to a java program?

0

I have the following code to put audio to an application that I am developing, the problem is that it sends me the following error

  

Exception in thread "main" java.lang.NoClassDefFoundError:   org / apache / commons / logging / LogFactory at   javazoom.jlgui.basicplayer.BasicPlayer. (Unknown Source) at   music.musica2. (musica2.java:12) at   musica.musica2.main (musica2.java:39) Caused by:   java.lang.ClassNotFoundException:   org.apache.commons.logging.LogFactory at   java.net.URLClassLoader.findClass (Unknown Source) at   java.lang.ClassLoader.loadClass (Unknown Source) at   sun.misc.Launcher $ AppClassLoader.loadClass (Unknown Source) at   java.lang.ClassLoader.loadClass (Unknown Source) ... 3 more

I do not know what I'm doing wrong, any ideas?

package musica;

import java.io.File;

import javazoom.jlgui.basicplayer.BasicPlayer;

public class musica2
{
  private BasicPlayer player;

     public musica2()
     {
      player=new BasicPlayer(); 
     }

    public void Play() throws Exception 
    {
     player.play();
    }

    public void AbrirFichero(String ruta) throws Exception {
      player.open(new File(ruta));
    }

    public void Pausa() throws Exception {
      player.pause();
    }

    public void Continuar() throws Exception {
      player.resume();
    }

    public void Stop() throws Exception {
      player.stop();
    }

    public static void main(String[] args) 
    {
    try {
          musica2 mi_reproductor = new musica2();
          mi_reproductor.AbrirFichero("c:/mi_archivo_de_musica.mp3");
          mi_reproductor.Play();
        } catch (Exception ex) {
          System.out.println("Error: " + ex.getMessage());
        }
   }

}
    
asked by vegetto 23.12.2017 в 01:54
source

1 answer

0

For what you are missing include libraries. I did a test to run the player and it requires the following:

  • basicplayer3.0.jar
  • commons-loggin-api-1.1.jar (due to missing this you are showing the exception you show)
  • jl1.0.jar
  • msp3spi1.9.2.jar
  • tritonus_share.jar
  • Next a capture with the player above and the libraries that are necessary to link to the project are marked

    This is the link to the documentation, some other libraries are mentioned (Required libraries section) but the ones indicated above are the ones necessary for your example to work. I tried my example with an .mp3 file and it went OK.

    link

    A comment ... for a convention topic it is recommended that the names of classes start with capital letters, in my example the class is called Music2 and therefore also the constructor.

    Greetings and I hope it is of your use.

        
    answered by 07.03.2018 в 21:44