问题描述
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null ;
尝试
{
BGM = 新 AudioStream ( new FileInputStream( / res / music.wav 跨度>));
MD = BGM.getData();
loop = new ContinuousAudioDataStream(MD);
}
catch (IOException e)
{
System。 out .println( 无法找到文件);
}
MGP.start(循环);
}
它总是打印我找不到文件,但我将此文件添加到我的项目
这是我的主要功能:
我尝试了什么:
i试试这个选项:
BGM =新的AudioStream(新的FileInputStream(music.wav));
BGM =新的AudioStream(新的FileInputStream(/ music.wav));
BGM =新的AudioStream(新的FileInputStream(音乐));
BGM =新的AudioStream(新的FileInputStream(我的computer.wav上的所有url路径));
i尝试将它放在项目的文件夹中并尝试以上所有但仍然工作
public static void music() { AudioPlayer MGP = AudioPlayer.player; AudioStream BGM; AudioData MD; ContinuousAudioDataStream loop = null; try { BGM = new AudioStream(new FileInputStream("/res/music.wav")); MD = BGM.getData(); loop = new ContinuousAudioDataStream(MD); } catch(IOException e) { System.out.println("cant find the file"); } MGP.start(loop); }
its always print me cant find the file but i add this file to my project
this is my main function :
What I have tried:
i try this option :
BGM = new AudioStream(new FileInputStream("music.wav"));
BGM = new AudioStream(new FileInputStream("/music.wav"));
BGM = new AudioStream(new FileInputStream("music"));
BGM = new AudioStream(new FileInputStream("all the url path at my computer.wav"));
i try to put it just in the folder of the project and tryied all above but still itd dosen work
这篇关于如何添加背景音乐到java游戏plz帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!