Corrigé le bug dans ControleurSon
This commit is contained in:
parent
bf4ddbd5e8
commit
911c161ab3
|
|
@ -2,6 +2,9 @@ package controleur;
|
|||
import vue.SoundPlayer;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
|
||||
// Une classe SoundManager qui gère les sons du jeu
|
||||
public class ControleurSon {
|
||||
|
|
@ -18,11 +21,9 @@ public class ControleurSon {
|
|||
final String BIP_ATTAQUE = "/musique/bipAttaque.wav";
|
||||
final String BIP_BONUS = "/musique/bipBonus.wav";
|
||||
|
||||
System.out.println(ControleurSon.class.getResource(MUSIQUE_FOND).getPath());
|
||||
|
||||
musiqueFond = new SoundPlayer(Objects.requireNonNull(ControleurSon.class.getResource(MUSIQUE_FOND).getPath()));
|
||||
bipAttaque = new SoundPlayer(Objects.requireNonNull(ControleurSon.class.getResource(BIP_ATTAQUE).getPath()));
|
||||
bipBonus = new SoundPlayer(Objects.requireNonNull(ControleurSon.class.getResource(BIP_BONUS).getPath()));
|
||||
musiqueFond = new SoundPlayer(getAbsolutePath(MUSIQUE_FOND));
|
||||
bipAttaque = new SoundPlayer(getAbsolutePath(BIP_ATTAQUE));
|
||||
bipBonus = new SoundPlayer(getAbsolutePath(BIP_BONUS));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -63,4 +64,15 @@ public class ControleurSon {
|
|||
bipBonus.stopSound();
|
||||
}
|
||||
|
||||
// helper method to get the absolute path of a file
|
||||
private String getAbsolutePath(String fileName) {
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = getClass().getResource(fileName).toURI();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new File(uri).getAbsolutePath();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue