Java Code Examples for com.badlogic.gdx.audio.Sound#play()

The following examples show how to use com.badlogic.gdx.audio.Sound#play() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoundEffect.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public static long play (Sound sound, float volume) {
	if (URacer.Game.isDesktop()) {
		return sound.play(volume);
	} else {
		int waitCounter = 0;
		long soundId = 0;

		boolean ready = false;
		while (!ready && waitCounter < WaitLimit) {
			soundId = sound.play(volume);
			ready = (soundId != 0);
			waitCounter++;
			try {
				Thread.sleep(ThrottleMs);
				// Gdx.app.log( "CarSoundEffect", "sleeping" );
			} catch (InterruptedException e) {
			}
		}

		return soundId;
	}
}
 
Example 2
Source File: AudioGdxSoundTest.java    From gdx-pd with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	
	new LwjglApplication(new Game(){
		@Override
		public void create() {
			
			// play a pd patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
			// and sounds at the same time
			final Sound snd = Gdx.audio.newSound(Gdx.files.classpath("shotgun.wav"));
			snd.play();
			Gdx.input.setInputProcessor(new InputAdapter(){
				@Override
				public boolean touchDown(int screenX, int screenY, int pointer, int button) {
					snd.play();
					return true;
				}
			});
			
		}}, config);
	
}
 
Example 3
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void play(Sound pcm, int channel, float volume, float pitch) {
	if(soundthread) {
		mixer.put(pcm, channel, volume, getGlobalPitch() * pitch);
	} else {
		synchronized (lock) {
			sounds[soundPos].sound = pcm;
			sounds[soundPos].id = pcm.play(volume, getGlobalPitch() * pitch, 0);
			sounds[soundPos].channel = channel;
			soundPos = (soundPos + 1) % sounds.length;
		}
	}
}
 
Example 4
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public long playSound(String soundName) {
    Sound sound = sounds.get(soundName);
    if (sound == null) {
        Logger.error("there is no sound for " + soundName);
        return -1;
    }
    return sound.play(volume);
}
 
Example 5
Source File: NinjaRabbitAudioProcessor.java    From ninja-rabbit with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(final Entity character) {
	if (character.isInState(NinjaRabbitState.JUMP) && character.getBody().getLinearVelocity().y > 0) {
		if (jumpTimeout <= 0) {
			Sound jumpFx = assets.get(Assets.JUMP_FX);
			jumpFx.stop(jumpFxId);
			jumpFxId = jumpFx.play();
			jumpTimeout = MAX_JUMP_TIMEOUT;
		} else {
			jumpTimeout -= Gdx.graphics.getDeltaTime();
		}
	} else {
		jumpTimeout = 0;
	}
}
 
Example 6
Source File: SoundManager.java    From xibalba with MIT License 4 votes vote down vote up
public void unarmed() {
  Sound sound = unarmed.get(MathUtils.random(0, unarmed.size - 1));
  sound.play(MathUtils.random(.3f, 1f));
}
 
Example 7
Source File: SoundManager.java    From xibalba with MIT License 4 votes vote down vote up
public void piercing() {
  Sound sound = piercing.get(MathUtils.random(0, piercing.size - 1));
  sound.play(MathUtils.random(.3f, 1f));
}
 
Example 8
Source File: Sounds.java    From GdxDemo3D with Apache License 2.0 4 votes vote down vote up
private static Sound load(String file) {
	Sound sound = Gdx.audio.newSound(Gdx.files.internal(file));
	sound.play(0); // this should force loading on Android, so avoiding the wait on first play in game
	return sound;
}
 
Example 9
Source File: GameManager.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
public void playSound(String soundName, float volume, float pitch, float pan) {
    Sound sound = assetManager.get(soundPath + soundName, Sound.class);
    sound.play(volume, pitch, pan);
}
 
Example 10
Source File: AudioUtils.java    From martianrun with Apache License 2.0 4 votes vote down vote up
public void playSound(Sound sound) {
    boolean soundOn = getPreferences().getBoolean(SOUND_ON_PREFERENCE, true);
    if (soundOn) {
        sound.play();
    }
}
 
Example 11
Source File: Assets.java    From ashley-superjumper with Apache License 2.0 4 votes vote down vote up
public static void playSound (Sound sound) {
	if (Settings.soundEnabled) sound.play(1);
}