Ola… fiz algumas mudanças no código, mas ainda não funciona… alguém pode
dar uma luz ?
A classe abaixo é uma Thread… quando o método fatalitySound() ou hitSound()
for chamado, quero que reproduza o audio … o problema é que ele faz isso
apenas 1 vez… reproduz o audio uma vez e depois não mais… como se o
arquivo após reproduzido fosse fechado… alguém sabe o que é isso ?
import javax.sound.sampled.*;
import java.io.*;
public class Sons extends Thread{
private Object ob;
private String local2;
private String local;
private AudioInputStream fatality = null,hit=null;
private Clip fatal,hits;
private boolean canFatal=false,canHit=false;
public Sons(){
try{
ob=this.getClass().getResource(".");
local2=ob+"";
local=local2.substring(6,local2.length());
carregaSons(); }
catch(Exception e){} }
public void carregaSons() throws Exception{
try {
fatality = AudioSystem.getAudioInputStream(new
File(local+"Sonsfatality.wav"));
hit= AudioSystem.getAudioInputStream(new
File(local+"Sonshit.wav"));
fatal = (Clip) AudioSystem.getLine(new
DataLine.Info(Clip.class,fatality.getFormat()));
hits= (Clip) AudioSystem.getLine(new
DataLine.Info(Clip.class,hit.getFormat()));
hits.open(hit);
fatal.open(fatality);
} catch (Exception excecao) {
excecao.printStackTrace(); }
}
public void fatalitySound() throws Exception{
canFatal=true; }
public void hitSound() throws Exception{
canHit=true; }
public void run(){
try{
while(true){
if(canHit){
hits.start();
canHit=false;}
if(canFatal){
fatal.start();
canFatal=false; }
}} catch(Exception ex){}
} }