diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2024-07-08 02:41:31 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2024-07-08 02:41:31 -0400 |
commit | ee2229339429d50afa33e2f8b9c0ee0939766290 (patch) | |
tree | a5ee54bd23c24950e9b10815f3e87605906992d8 /src/main/SoundController.java | |
parent | 9e1371424bdf4c31d756d686313730d4c61f7ac5 (diff) | |
download | NPEhero-ee2229339429d50afa33e2f8b9c0ee0939766290.tar.gz NPEhero-ee2229339429d50afa33e2f8b9c0ee0939766290.tar.bz2 NPEhero-ee2229339429d50afa33e2f8b9c0ee0939766290.zip |
Change project structure, embed resources into jar and remove libraries from source control
Diffstat (limited to '')
-rwxr-xr-x[-rw-r--r--] | src/main/java/net/sowgro/npehero/main/SoundController.java (renamed from src/main/SoundController.java) | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/main/SoundController.java b/src/main/java/net/sowgro/npehero/main/SoundController.java index 0d7527e..da80ab4 100644..100755 --- a/src/main/SoundController.java +++ b/src/main/java/net/sowgro/npehero/main/SoundController.java @@ -1,10 +1,12 @@ -package main; +package net.sowgro.npehero.main; import java.io.File; +import java.net.URISyntaxException; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; -import gui.Driver; +import net.sowgro.npehero.Driver; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.util.Duration; @@ -13,19 +15,27 @@ public class SoundController { public MediaPlayer songMediaPlayer; public MediaPlayer sfxMediaPlayer; - private HashMap<String,MediaPlayer> effects = new HashMap<>(); - private File mainMenuSong = Paths.get("resources/fairyfountain.wav").toFile(); - + private final HashMap<String,MediaPlayer> effects = new HashMap<>(); + private final File mainMenuSong; + + { + try { + mainMenuSong = new File(Driver.getResource("fairyfountain.wav").toURI()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + /** * creates a new sound controller and starts playing the main menu music */ public SoundController() { - effects.put("hit", new MediaPlayer(new Media(Paths.get("resources/hit.wav").toUri().toString()))); - effects.put("miss", new MediaPlayer(new Media(Paths.get("resources/miss.wav").toUri().toString()))); - effects.put("forward", new MediaPlayer(new Media(Paths.get("resources/forward.wav").toUri().toString()))); - effects.put("backward", new MediaPlayer(new Media(Paths.get("resources/backward.wav").toUri().toString()))); + effects.put("hit", new MediaPlayer(new Media(Driver.getResource("hit.wav").toString()))); + effects.put("miss", new MediaPlayer(new Media(Driver.getResource("miss.wav").toString()))); + effects.put("forward", new MediaPlayer(new Media(Driver.getResource("forward.wav").toString()))); + effects.put("backward", new MediaPlayer(new Media(Driver.getResource("backward.wav").toString()))); effects.forEach((key,value) -> { value.volumeProperty().bind(Driver.settingsController.effectsVol); }); @@ -53,6 +63,10 @@ public class SoundController */ public void playMenuSong() { + if (!mainMenuSong.exists()) { + System.out.println("NOT EXIST " + mainMenuSong.getAbsolutePath()); + return; + } playSong(mainMenuSong); songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); songMediaPlayer.play(); @@ -71,7 +85,7 @@ public class SoundController /** * plays a sound effect - * for the volume slider to take affect each mediaplayer needs to be pre loaded. + * for the volume slider to take effect each mediaplayer needs to be preloaded. * this rewinds and played the proper mediaplayer for the sound * @param preset: a string of the name of the sound. possible sounds assigned in the constructor */ |