播放背景音乐的节目

时间:2013-08-10 15:17:14

标签: java audio

我使用Eclipse Juno并收到以下错误:

Access restriction:The type AudioPlayer is not accessible due to restriction 
    on required library C:\Program\Files\Java\jre6\lib\rt.jar

AudioStreamAudioData非常相似。

如何解决这些错误?

1 个答案:

答案 0 :(得分:0)

你试过AudioClip吗?

public static final Sound sound= new Sound("/sound.wav");

private AudioClip clip;

private Sound(String name) {
    try {
        clip = Applet.newAudioClip(Sound.class.getResource(name));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

public void play() {
    try {
        new Thread() {
            public void run() {
                clip.play();
            }
        }.start();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}