Java:完成播放后循环播放声音

时间:2015-02-02 17:50:20

标签: java audio

我有一个包含标题屏幕的程序。在所述标题屏幕中,我希望音乐循环播放。我已经创建了一个音乐文件,它大约有10秒钟。我希望它在完成时不断重复,但我不知道如何检查它是否已完成或如何循环它。

这是我的声音课程:

public class Sound {

    public static final Sound cash = new Sound("/cash.wav");
    public static final Sound snap = new Sound("/snap.wav");
    public static final Sound disarm = new Sound("/disarm.wav");
    public static final Sound tp = new Sound("/tp.wav");
    public static final Sound select = new Sound("/selectBTN.wav");
    public static final Sound scroll = new Sound("/btn.wav");
    public static final Sound fire = new Sound("/fire2.wav");

    public static final Sound titlemusic = new Sound("/music/TitleMusic.wav");

    private AudioClip c;

    public Sound(String filename) {
        try {
            c = Applet.newAudioClip(Sound.class.getResource(filename));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void play() {
        try {
            new Thread() {
                public void run() {
                    if (!title.mute) {

                        c.play();


                    }
                }
            }.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

当我想播放时,我告诉它播放这样的声音:

        Sound.titlemusic.play();

0 个答案:

没有答案