aboutsummaryrefslogtreecommitdiff
path: root/src/main/SoundController.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-06-05 00:34:16 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-06-05 00:34:16 -0400
commita14862a6bc0dbb1ae78cd4e2e4795d4194772583 (patch)
tree88db04cdcc76454ae0f0025a9249270fab45ee22 /src/main/SoundController.java
parentd87a87aabde8b4011910dfed731362b7cf0b6b24 (diff)
downloadNPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.tar.gz
NPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.tar.bz2
NPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.zip
rewrote everything related to sound
Diffstat (limited to 'src/main/SoundController.java')
-rw-r--r--src/main/SoundController.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/SoundController.java b/src/main/SoundController.java
new file mode 100644
index 0000000..55d40f4
--- /dev/null
+++ b/src/main/SoundController.java
@@ -0,0 +1,66 @@
+package main;
+
+import java.io.File;
+import java.util.HashMap;
+
+import gui.Driver;
+import javafx.scene.media.Media;
+import javafx.scene.media.MediaPlayer;
+
+public class SoundController
+{
+ public MediaPlayer songMediaPlayer;
+ public MediaPlayer sfxMediaPlayer;
+ private HashMap<String,File> presets = new HashMap<>();
+ private File mainMenuSong = new File("src/assets/MenuMusicPlaceholder.wav");
+
+ public SoundController()
+ {
+ presets.put("forward", new File("src/assets/MenuForward.wav"));
+ presets.put("backward", new File("src/assets/MenuBackward.wav"));
+ presets.put("hit", new File("src/assets/Hitsound.wav"));
+ presets.put("miss", new File("src/assets/Miss.wav"));
+ playMenuSong();
+ }
+
+ public void playSong(File songFile)
+ {
+ if (songMediaPlayer != null)
+ {
+ songMediaPlayer.stop();
+ }
+ Media song = new Media(songFile.toURI().toString());
+ songMediaPlayer = new MediaPlayer(song);
+ songMediaPlayer.volumeProperty().bind(Driver.settingsController.musicVol);
+ songMediaPlayer.play();
+ }
+
+ private void playMenuSong()
+ {
+ playSong(mainMenuSong);
+ songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
+ songMediaPlayer.play();
+ }
+
+ public void endSong()
+ {
+ playMenuSong();
+ }
+
+ public void playSfx(File sfxFile)
+ {
+ if (sfxMediaPlayer != null)
+ {
+ sfxMediaPlayer.stop();
+ }
+ Media sound = new Media(sfxFile.toURI().toString());
+ sfxMediaPlayer = new MediaPlayer(sound);
+ sfxMediaPlayer.volumeProperty().bind(Driver.settingsController.effectsVol); //not working yet
+ sfxMediaPlayer.play();
+ }
+
+ public void playSfx(String preset)
+ {
+ playSfx(presets.get(preset));
+ }
+} \ No newline at end of file