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
Branches master
No related tags found
1 merge request!26Resolve "Add more sounds"
......@@ -5,6 +5,7 @@ import javafx.scene.media.Media;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class SoundController{
private List<String> sounds = new ArrayList<>();
......@@ -12,7 +13,10 @@ public class SoundController{
//Creating Singleton
private static final SoundController INSTANCE = new 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(){
return INSTANCE;
......@@ -23,7 +27,7 @@ public class SoundController{
this.sounds.add(file);
}
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.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