gpt4 book ai didi

java - 我正在尝试在 Applet 中添加音频 url

转载 作者:行者123 更新时间:2023-12-01 14:45:20 25 4
gpt4 key购买 nike

我在将音频文件 URL 放入我的 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)

我按照在线教程进行操作,并且正确且完整地遵循了它。但是缺少/错误的是什么呢?

最佳答案

您遵循了什么教程?您阅读了 getCodeBase 和 AudioClip 的 javadoc 了吗?

我认为这是你应该做的:

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

这首歌应该位于您的类文件目录中。我没有尝试过,但我认为它应该有效。

关于java - 我正在尝试在 Applet 中添加音频 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15479719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com