我想在Applet中放一个音频网址

时间:2013-03-18 14:49:20

标签: java user-interface audio applet

我无法在我的getCodeBase方法中将音频文件网址放入我的应用中:

public class Audioapp extends JApplet
{
    public class Sound // Holds one audio file
    {
        private AudioClip song; // Sound player
        private URL songPath; // Sound path
        Sound(String filename)
        {
            try
            {
                songPath = new URL(getCodeBase("G:\\Uni\\Programming\\Rolling assignements\\Week0\\Programming week21"),filename);  // This is the place were im getting error
                song = Applet.newAudioClip(songPath); // Load the Sound
            }
            catch(Exception e){e.printStackTrace();} 
        }
        public void playSound()
        {
            song.play(); // Play
        }
    }
}

我得到的错误是:

The method getCodeBase() in the type Applet is not applicable for the arguments (String)

我在线跟踪了教程,并且已经完整地跟踪了它。但缺少/错误的是什么?

2 个答案:

答案 0 :(得分:1)

你遵循了什么教程? 你读过getCodeBase和AudioClip的javadoc吗?

我认为这是你应该做的:

Audioclip song = getAudioClip(getCodeBase(),"filename");

这首歌应该在你的班级文件目录中。 我没试过,但我认为它应该有效。

答案 1 :(得分:0)

根据Oracle的Java API for Applets,没有方法可以传递字符串。 有三种方法没有任何参数。

相关问题