How to use a thread that has died again?

0

I'm making an application that plays sound effects for an RPG game. The goal is for the application to be able to play multiple sounds simultaneously (a song together with an explosion effect, for example).

Each time the user clicks on the button, the soundtrack must be triggered. To end, you must click again. The problem is that after running Thread for the first time, I can not run it again.

The code of the class that plays the audio is as follows:

public class TocaAudio implements Runnable{
    private Player player;
    private final Trilha TRILHA;

    public TocaAudio(Trilha trilha) {
       this.TRILHA = trilha;
    }

    @Override
    public void run() {
        try {
            player = new Player(this.TRILHA.getArquivo());
            player.play();
        } catch (FileNotFoundException | JavaLayerException e) {
            e.printStackTrace();
        }
    }     
}

And the part that runs Thread is as follows:

Trilha trilhaChuva = new Trilha("src/br/com/rpgtrilhassonoras/files/sounds/chuva.mp3");
Thread audioChuva = new Thread(new TocaAudio(trilhaChuva));

private void btnChuvaActionPerformed(java.awt.event.ActionEvent evt) {                                         
    if(audioChuva.isAlive()) {
        audioChuva.stop();
        btnStatus.desativado(btnChuva);
    } else {
        audioChuva.start();
        btnStatus.ativado(btnChuva);    
    }
}  

Thank you for your attention!

    
asked by anonymous 21.12.2017 / 18:48

0 answers