我正在制作基于玩家的平铺游戏,我想将音乐添加到GameState的背景中。但是,当我上传Sound类时:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
public class Sound {
public static void music() {
try{
File file = new File("resources/bracho.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
try{
Player player = new Player(bis);
player.play();
}
catch(JavaLayerException e){
}
}
catch(FileNotFoundException e){
}
}
}
这是init()方法:
private void initilization() {
frame = new Frame(title, width, height);
frame.getFrame().addKeyListener(keyM);
Assets.initilization();
screenMover = new MoveScreen(this,1,1);
handler = new Handler(this);
boardState = new BoardState(handler);
mainMenuState = new MainMenuState(handler);
settingsState = new SettingsState(handler);
State.setState(boardState);
Sound.music();
}
声音确实有效,但是没有一个gui被画在屏幕上,只是音乐和音乐都很好。所以起初我认为问题是音乐文件太大所以我把文件缩小到500kb仍然有问题。然后我让它多线程,它仍然有问题。
有什么想法吗? 谢谢!