How to automatically pause an audio in java netbeans?

2

Good day, I know very little about programming, I'm doing a project in netbeans in java with a Jframe, where through a list box you select a concept and hear an audio there Everything is fine until I select another audio and the sounds come together distorting completely Is there any way to pause an audio when changing options? I would thank you a lot This is my code

   String ruta2 = "G://Proyecto//src//Sonidos e imagenes//Sonidos//Digestivo";

This is the route where the audios are located

   private void lstProcesosMousePressed(java.awt.event.MouseEvent evt) {                                         

    String Archivo = ruta2 + "//" + lstProcesos.getSelectedValue() + ".wav";

    try{
        Clip sonido=AudioSystem.getClip();
        sonido.open(AudioSystem.getAudioInputStream(new File(Archivo)));
        sonido.start();
    } catch (Exception e){
        System.out.println(""+e);

    }

}                                        
    
asked by Hana Mtz 15.11.2018 в 03:39
source

1 answer

1

You must use the method stop ( )

sonido.stop()

You must stop the audio and play again by start()

    
answered by 15.11.2018 в 03:59