2019-04-14 12:18:58 +02:00

47 lines
928 B
Java

package mod_audio;
import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import mod_audio.AudioPlayer;
public class Music {
private File audiofile;
private Clip clip;
Thread sound;
private AudioPlayer ap;
public Music(String filename) {
this.audiofile = new File(filename);
try {
this.clip = AudioSystem.getClip();
this.clip.open(AudioSystem.getAudioInputStream(this.audiofile));
}
catch (Exception e) {
e.printStackTrace();
}
this.ap = new AudioPlayer(this.clip);
this.sound = new Thread(this.ap);
}
public void play() {
this.sound.start();
}
public void loop() {
this.ap.setLoop(true);
this.sound.start();
}
public void stop() {
this.clip.close();
}
}