title: Run audio files on a .jar
body: <p>Good evening, please someone could tell me how the audio files are executed in a .jar</p>
  
  <p>I have tried to call them using getClass (). GetResource () but I can not use it since an error appears.</p>
  
  <p>This is my implementation for playing sounds:</p>
  
  <pre><code>public class Sonido extends Thread {
  
  private Clip sonido;
  
  private boolean seguir;
  
  public Sonido(String rutaArchivo){        
      try {
  
          sonido = AudioSystem.getClip();
  
          sonido.open(AudioSystem.getAudioInputStream(new File(rutaArchivo)));
  
      } catch (UnsupportedAudioFileException | IOException | LineUnavailableException ex) {
  
          Logger.getLogger(PanelBotones.class.getName()).log(Level.SEVERE, null, ex);
  
      }
  
   }
  
  @Override
  @SuppressWarnings("SleepWhileInLoop")
  public void run() {
  
      seguir = true;
  
      do {
  
          sonido.loop(0);
  
          try {
  
              Thread.sleep(1000);
  
          } catch (InterruptedException interruptedException) {
  
              Logger.getLogger(PanelBotones.class.getName()).log(Level.SEVERE, null,
                      interruptedException);
  
          }
  
      } while (seguir == true &amp;&amp; sonido.isActive());
  
      // Se cierra el clip.
      sonido.close();
  
  }
  
  public void parar() {
  
      seguir = false;
  
     }
  
  }
  </code></pre>
  
  <p>And this is the event method where you created the new clip</p>
  
  <pre><code>@Override
  public void actionPerformed(ActionEvent e) {
  
      String cadena = e.getActionCommand();
  
      if (cadena.equalsIgnoreCase(ROJO)) {
  
          interfazPrincipal.imagenUno();
  
          sonido = new Sonido("./recursos/sonido/rojo.wav");
  
          Thread cancionFondo;
  
          cancionFondo = new Thread(sonido);
  
          cancionFondo.start();
  
  
      }
  </code></pre>
  
  <p>I would be appreciated for your help, thank you.</p>