autostart main theme
This commit is contained in:
49
src/de/miaurizius/jgame2d/core/Sound.java
Normal file
49
src/de/miaurizius/jgame2d/core/Sound.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package de.miaurizius.jgame2d.core;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Sound {
|
||||
|
||||
Clip clip;
|
||||
URL[] soundURL = new URL[30];
|
||||
|
||||
public Sound() {
|
||||
try {
|
||||
soundURL[0] = new File("assets/sounds/BlueBoyAdventure.wav").toURI().toURL();
|
||||
soundURL[1] = new File("assets/sounds/coin.wav").toURI().toURL();
|
||||
soundURL[2] = new File("assets/sounds/powerup.wav").toURI().toURL();
|
||||
soundURL[3] = new File("assets/sounds/unlock.wav").toURI().toURL();
|
||||
soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL();
|
||||
} catch(MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFile(int i) {
|
||||
try {
|
||||
AudioInputStream ais = AudioSystem.getAudioInputStream(soundURL[i]);
|
||||
clip = AudioSystem.getClip();
|
||||
clip.open(ais);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
clip.start();
|
||||
}
|
||||
|
||||
public void loop() {
|
||||
clip.loop(Clip.LOOP_CONTINUOUSLY);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
clip.stop();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user