Clip Class when playing a .wav does not play sound

2

When playing a .wav file, sounds are not played, but in netbeans if:

This is my code:

public Clip clip;

public void ponerMusica(String musica) {
    try {
        clip = AudioSystem.getClip();
        clip.open(AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/Sonidos/" + musica + ".wav")));
        clip.start();
    } catch (IOException | LineUnavailableException | UnsupportedAudioFileException e) {

    }
}
    
asked by TOPOFGR 26.11.2018 в 19:39
source

1 answer

3

This is a known problem that is related to the repositionable property of InputStream

link

In this case if your InputStream does not have this property it is not advisable to use the getResourceAsStream

clip.open(AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/Sonidos/" + musica + ".wav")));

If your InputStream is not repositionable, you can use a workaround and use getResource () :

 clip.open(AudioSystem.getAudioInputStream(getClass().getResource("/Sonidos/" + musica + ".wav")));
    
answered by 06.12.2018 в 02:59