From 911c161ab362ce34ec6de3859fcc5849c922a4ce Mon Sep 17 00:00:00 2001 From: amaury Date: Mon, 1 May 2023 21:18:51 +0200 Subject: [PATCH] =?UTF-8?q?Corrig=C3=A9=20le=20bug=20dans=20ControleurSon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controleur/ControleurSon.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/controleur/ControleurSon.java b/src/controleur/ControleurSon.java index 544e28f..07f8652 100644 --- a/src/controleur/ControleurSon.java +++ b/src/controleur/ControleurSon.java @@ -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(); + } + }