-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement functionality for audio and sound effects
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Audio/AudioManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Audio; | ||
|
|
||
| import javafx.scene.media.AudioClip; | ||
|
|
||
| import java.util.EnumMap; | ||
| import java.util.Map; | ||
|
|
||
| public class AudioManager { | ||
|
|
||
| private AudioManager instance = new AudioManager(); | ||
| private Map<SoundEffect, AudioClip> sounds = new EnumMap<>(SoundEffect.class); | ||
| private double volume = 1.0; | ||
|
|
||
| public AudioManager() { | ||
|
|
||
| for (SoundEffect effect : SoundEffect.values()) { | ||
|
|
||
| AudioClip clip = new AudioClip( | ||
| getClass() | ||
| .getResource(effect.getPath()) | ||
| .toExternalForm() | ||
| ); | ||
|
|
||
| sounds.put(effect, clip); | ||
| } | ||
| } | ||
|
|
||
| public AudioManager getInstance() { | ||
| return instance; | ||
| } | ||
|
|
||
| public void play(SoundEffect sound) { | ||
| AudioClip audioClip = sounds.get(sound); | ||
|
|
||
| if (audioClip != null) { | ||
| audioClip.play(volume); | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Audio/SoundEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Audio; | ||
|
|
||
| public enum SoundEffect { | ||
|
|
||
| OPEN_APP("/Audio/mouse_click.wav"), | ||
| CLOSE_APP("/Audio/mouse_click.wav"); | ||
|
|
||
| private String path; | ||
|
|
||
| SoundEffect(String path) { | ||
| this.path = path; | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
| } |
File renamed without changes.
Binary file not shown.