Skip to content
Snippets Groups Projects
Commit 366f810e authored by Anders Langlie's avatar Anders Langlie :crab:
Browse files

Merge branch '22-add-more-sounds' into 'master'

Resolve "Add more sounds"

Closes #22

See merge request !26
parents 101a95e9 b3c50f92
No related branches found
No related tags found
1 merge request!26Resolve "Add more sounds"
...@@ -5,6 +5,7 @@ import javafx.scene.media.Media; ...@@ -5,6 +5,7 @@ import javafx.scene.media.Media;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class SoundController{ public class SoundController{
private List<String> sounds = new ArrayList<>(); private List<String> sounds = new ArrayList<>();
...@@ -12,7 +13,10 @@ public class SoundController{ ...@@ -12,7 +13,10 @@ public class SoundController{
//Creating Singleton //Creating Singleton
private static final SoundController INSTANCE = new SoundController(); private static final SoundController INSTANCE = new SoundController();
private SoundController(){ private SoundController(){
addSound("./src/sample/woosh.mp3"); addSound("./src/sample/woosh1.mp3");
addSound("./src/sample/woosh2.mp3");
addSound("./src/sample/woosh3.mp3");
addSound("./src/sample/woosh4.mp3");
} }
public static SoundController getInstance(){ public static SoundController getInstance(){
return INSTANCE; return INSTANCE;
...@@ -23,7 +27,7 @@ public class SoundController{ ...@@ -23,7 +27,7 @@ public class SoundController{
this.sounds.add(file); this.sounds.add(file);
} }
public void playSound(){ public void playSound(){
Media sound = new Media(new File(sounds.get(0)).toURI().toString()); Media sound = new Media(new File(sounds.get(ThreadLocalRandom.current().nextInt(0, sounds.size()))).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound); MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.play(); mediaPlayer.play();
} }
......
File moved
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment