Skip to content
Snippets Groups Projects
Commit 96c179da authored by Eirik Martin Danielsen's avatar Eirik Martin Danielsen :speech_balloon:
Browse files

soundcontroller

parent 718a2b16
No related branches found
No related tags found
1 merge request!25Resolve "soundeffects"
package sample;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.Media;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SoundController{
private List<String> sounds = new ArrayList<>();
//Creating Singleton
private static final SoundController INSTANCE = new SoundController();
private SoundController(){
addSound("woosh.mp3");
}
public static SoundController getInstance(){
return INSTANCE;
}
//End Singleton
public void addSound(String file){
this.sounds.add(file);
}
public void playSound(){
Media sound = new Media(new File(sounds.get(0)).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.play();
}
}
\ No newline at end of file
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