本文整理汇总了Java中org.newdawn.slick.openal.Audio类的典型用法代码示例。如果您正苦于以下问题:Java Audio类的具体用法?Java Audio怎么用?Java Audio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Audio类属于org.newdawn.slick.openal包,在下文中一共展示了Audio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAudio
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
/**
* 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;
}
}
示例2: loadSound
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static AudioData loadSound(String ref) throws SlickException {
SoundStore.get().init();
Audio audio = null;
try {
if (ref.toLowerCase().endsWith(".ogg")) {
audio = SoundStore.get().getOgg(ref);
} else if (ref.toLowerCase().endsWith(".wav")) {
audio = SoundStore.get().getWAV(ref);
} else if (ref.toLowerCase().endsWith(".aif")) {
audio = SoundStore.get().getAIF(ref);
} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
throw new SlickException("Use XStream for streaming .xm and .mod sounds");
} else {
throw new SlickException("Only .xm, .mod, .aif, .wav and .ogg are currently supported.");
}
} catch (Exception e) {
Log.error(e);
throw new SlickException("Failed to load sound: " + ref, e);
}
return new AudioData(audio.getBufferID());
}
示例3: getAudio
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
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;
}
}
示例4: Sounds
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public Sounds() throws IOException {
soundEnabled = true;
musicEnabled = true;
acceptSound = loadAudio("resources/sounds/menu-validate.wav");
declineSound = loadAudio("resources/sounds/menu-back.wav");
cursorSound = loadAudio("resources/sounds/menu-nav.wav");
boingSound = loadAudio("resources/sounds/boing.wav");
pointSound = loadAudio("resources/sounds/mouthpop.wav");
hitSounds = new Audio[3];
hitSounds[0] = loadAudio("resources/sounds/djembe-mid-4.wav");
hitSounds[1] = loadAudio("resources/sounds/djembe-hi-3.wav");
hitSounds[2] = loadAudio("resources/sounds/djembe-mid-2.wav");
pointsPowerupSound = loadAudio("resources/sounds/goblet-g-medium.wav");
deathSound = loadAudio("resources/sounds/stone-on-stone-impact.wav");
winSound = loadAudio("resources/sounds/win.wav");
loseSound = loadAudio("resources/sounds/lose.wav");
music = loadAudio("resources/sounds/loop003-jungle.wav");
menuMusic = loadAudio("resources/sounds/przeszkadzajki.wav");
}
示例5: loop
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
/**
* 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){}
}
}
示例6: loadSound
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static void loadSound(NBMData data) throws IOException {
Map<Integer, String> soundMap = data.getSoundMap();
Map<Integer, Audio> soundDataMap = data.getSoundDataMap();
for (Map.Entry<Integer, String> entry : soundMap.entrySet()){
int key = entry.getKey();
String path = entry.getValue();
Audio audio = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream(data.getParentPath() + "/" + path));
soundDataMap.put(key, audio);
}
}
示例7: loop
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
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: restart
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
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();
}
}
示例9: playAudio
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static void playAudio(String name, float pitch, float gain, float x,
float y, float z, float fade) {
Audio audio = FEResources.getAudio(name);
float cx, cy;
if(camera == null) {
cx = Game.getWindowWidth()/2;
cy = Game.getWindowHeight()/2;
} else {
cx = camera.getX();
cy = camera.getY();
}
audio.playAsSoundEffect(pitch, gain + globalGain, false,
(x - cx) / fade, (y - cy) / fade, z);
}
示例10: getSoundPressArrows
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static Audio getSoundPressArrows() {
return soundPressArrows;
}
示例11: setSoundPressArrows
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static void setSoundPressArrows(Audio sound) {
soundPressArrows = sound;
}
示例12: getSoundPressEnter
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static Audio getSoundPressEnter() {
return soundPressEnter;
}
示例13: setSoundPressEnter
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
public static void setSoundPressEnter(Audio sound) {
soundPressEnter = sound;
}
示例14: destroyOpenAL
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
/**
* Stops and releases all sources, clears each of the specified Audio
* buffers, destroys the OpenAL context, and resets SoundStore for future use.
*
* Calling SoundStore.get().init() will re-initialize the OpenAL context
* after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
*
* @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
*/
private static void destroyOpenAL() {
if (!trackExists())
return;
stop();
try {
// get Music object's (private) Audio object reference
Field sound = player.getClass().getDeclaredField("sound");
sound.setAccessible(true);
Audio audio = (Audio) (sound.get(player));
// first clear the sources allocated by SoundStore
int max = SoundStore.get().getSourceCount();
IntBuffer buf = BufferUtils.createIntBuffer(max);
for (int i = 0; i < max; i++) {
int source = SoundStore.get().getSource(i);
buf.put(source);
// stop and detach any buffers at this source
AL10.alSourceStop(source);
AL10.alSourcei(source, AL10.AL_BUFFER, 0);
}
buf.flip();
AL10.alDeleteSources(buf);
int exc = AL10.alGetError();
if (exc != AL10.AL_NO_ERROR) {
throw new SlickException(
"Could not clear SoundStore sources, err: " + exc);
}
// delete any buffer data stored in memory, too...
if (audio != null && audio.getBufferID() != 0) {
buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
buf.flip();
AL10.alDeleteBuffers(buf);
exc = AL10.alGetError();
if (exc != AL10.AL_NO_ERROR) {
throw new SlickException("Could not clear buffer "
+ audio.getBufferID()
+ ", err: "+exc);
}
}
// clear OpenAL
AL.destroy();
// reset SoundStore so that next time we create a Sound/Music, it will reinit
SoundStore.get().clear();
player = null;
} catch (Exception e) {
explode("Failed to destroy OpenAL.", e, DEFAULT_OPTIONS);
}
}
示例15: playAudio
import org.newdawn.slick.openal.Audio; //导入依赖的package包/类
/**
* Play audio.
*
* @param name the name
*/
public static void playAudio(String name){
Audio audio = FEResources.getAudio(name);
audio.playAsSoundEffect(1.0f, FEResources.getAudioVolume(), false);
}