Java源码示例:org.newdawn.slick.openal.AudioLoader
示例1
/**
* Load resources.
*/
public static void loadResources() {
try {
//Load bitmap fonts
loadBitmapFonts();
// Textures
textures.put("whoops", new AnimationData("res/whoops.png"));
loadTextures();
//load audio
audio.put("miss", AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
} catch (IOException e) {
int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
System.out.println(max);
e.printStackTrace();
}
System.gc();
}
示例2
/**
* Gets the audio.
*
* @param name the name
* @return the audio
*/
public static Audio getAudio(String name) {
Audio a = audio.get(name);
if(a == null) {
// System.err.println("Warn: " + name + " not explicitly defined");
try{
Audio b = AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
audio.put(name, b);
return b;
} catch (Exception e){
return null;
}
} else {
return a;
}
}
示例3
public static void loadResources() {
try {
//Load bitmap fonts
loadBitmapFonts();
// Textures
textures.put("whoops", new AnimationData("res/whoops.png"));
loadTextures();
//load audio
audio.put("miss", AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
} catch (IOException e) {
int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
System.out.println(max);
e.printStackTrace();
}
System.gc();
}
示例4
public static Audio getAudio(String name) {
Audio a = audio.get(name);
if(a == null) {
// System.err.println("Warn: " + name + " not explicitly defined");
try{
Audio b = AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
audio.put(name, b);
return b;
} catch (Exception e){
return null;
}
} else {
return a;
}
}
示例5
/**
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
*/
public void init(GameContainer container) throws SlickException {
SoundStore.get().setMaxSources(32);
myContainer = container;
sound = new Sound("testdata/restart.ogg");
charlie = new Sound("testdata/cbrown01.wav");
try {
engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
} catch (IOException e) {
throw new SlickException("Failed to load engine", e);
}
music = musica = new Music("testdata/SMB-X.XM");
//music = musica = new Music("testdata/theme.ogg", true);
musicb = new Music("testdata/kirby.ogg", true);
burp = new Sound("testdata/burp.aif");
music.play();
}
示例6
/**
* Loops the given audio according to settings.
*
* @param name the music category
*/
public static void loop(String name){
if (FEResources.getAudioVolume() <= 0) return;
if (name.equals(currentName) && current.isPlaying()) return;
current.stop();
currentName = name;
Map<String, ArrayList<String>> songs = loadAudioNames();
try{
String setting = FEResources.getAudioSetting(name.toUpperCase());
if(setting.equals("random")){
Random r = new Random();
setting = name + "_" + songs.get(name).get(r.nextInt(songs.get(name).size()));
if(setting.split("_").length<2)
setting = name;
}
current = AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/music/"+setting+".wav"));
current.playAsMusic(1.0f, FEResources.getAudioVolume(), true);
} catch (Exception e){
e.printStackTrace();
System.err.println("Warn: Bad sound configuration: "+name);
try{
Audio b = AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/music/"+name+".wav"));
b.playAsMusic(1.0f, FEResources.getAudioVolume(), true);
}catch(Exception f){}
}
}
示例7
public static void loop(String name){
if(!enabled) return;
if(name.equals(current)) return;
try {
current = name;
Audio a = AudioLoader.getStreamingAudio("OGG",
ResourceLoader.getResource("res/music/"+name+".ogg"));
a.playAsMusic(1, 1, true);
} catch (IOException e) {
e.printStackTrace();
}
}
示例8
public static void restart(){
if(!enabled) return;
try {
Audio a = AudioLoader.getStreamingAudio("OGG",
ResourceLoader.getResource("res/music/"+current+".ogg"));
a.playAsMusic(1, 1, true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}