package main;

import javax.sound.sampled.*;
import java.io.IOException;
import java.net.URL;

public class Sound {
    Clip clip;
    URL[] soundUrl = new URL[30];

    public Sound() {
        soundUrl[0] = Sound.class.getResource("/sound/BlueBoyAdventure.wav");
        soundUrl[1] = Sound.class.getResource("/sound/coin.wav");
        soundUrl[2] = Sound.class.getResource("/sound/powerup.wav");
        soundUrl[3] = Sound.class.getResource("/sound/unlock.wav");
        soundUrl[4] = Sound.class.getResource("/sound/fanfare.wav");
    }
    public void setFile(int i){
        try {
            AudioInputStream ais = AudioSystem.getAudioInputStream(soundUrl[i]);
            clip = AudioSystem.getClip();
            clip.open(ais);
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }
    public void play() {
        clip.start();
    }
    public void loop() {
        clip.loop(Clip.LOOP_CONTINUOUSLY);
    }
    public void stop() {
        clip.stop();
    }
}
