com.badlogic.gdx.audio.Sound Java Examples

The following examples show how to use com.badlogic.gdx.audio.Sound. 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: SoundEffect.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public static long loop (Sound sound, float volume) {
	if (URacer.Game.isDesktop()) {
		return sound.loop(volume);
	} else {
		int waitCounter = 0;
		long soundId = 0;

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

		return soundId;
	}
}
 
Example #3
Source File: Button.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public Button(ButtonStyle style) {
  super(style);
  addListener(new ClickListener() {
    Sound button = null;

    {
      Riiablo.assets.load(buttonDescriptor);
    }

    @Override
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int b) {
      if (event.getButton() != Input.Buttons.LEFT || isDisabled()) {
        return super.touchDown(event, x, y, pointer, b);
      } else if (button == null) {
        Riiablo.assets.finishLoadingAsset(buttonDescriptor);
        button = Riiablo.assets.get(buttonDescriptor);
      }

      button.play();
      Riiablo.input.vibrate(10);
      return super.touchDown(event, x, y, pointer, b);
    }
  });
}
 
Example #4
Source File: PillSystem.java    From Pacman_libGdx with MIT License 6 votes vote down vote up
@Override
protected void processEntity(Entity entity, float deltaTime) {

    PillComponent pill = pillM.get(entity);
    MovementComponent movement = movementM.get(entity);

    Body body = movement.body;
    if (pill.eaten) {
        if (pill.big) {
            GameManager.instance.addScore(500);
            GameManager.instance.assetManager.get("sounds/big_pill.ogg", Sound.class).play();
        } else {
            GameManager.instance.addScore(100);
            GameManager.instance.assetManager.get("sounds/pill.ogg", Sound.class).play();
        }

        body.getWorld().destroyBody(body);
        getEngine().removeEntity(entity);

        GameManager.instance.totalPills--;
    }

}
 
Example #5
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 #6
Source File: GameManager.java    From Pacman_libGdx with MIT License 5 votes vote down vote up
private GameManager() {
    assetManager = new AssetManager();
    assetManager.load("images/actors.pack", TextureAtlas.class);
    assetManager.load("sounds/pill.ogg", Sound.class);
    assetManager.load("sounds/big_pill.ogg", Sound.class);
    assetManager.load("sounds/ghost_die.ogg", Sound.class);
    assetManager.load("sounds/pacman_die.ogg", Sound.class);
    assetManager.load("sounds/clear.ogg", Sound.class);

    assetManager.finishLoading();

    playerSpawnPos = new Vector2();
    ghostSpawnPos = new Vector2();
}
 
Example #7
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void stop(Sound id) {
	if (soundthread) {
		mixer.stop(id, 0);
	} else {
		synchronized (lock) {
			id.stop();			
		}			
	}
}
 
Example #8
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void stop(Sound id, int channel) {
	if (soundthread) {
		mixer.stop(id, channel);
	} else {
		for (int i = 0; i < sounds.length; i++) {
			if (sounds[i].sound == id && sounds[i].channel == channel) {
				synchronized (lock) {
					sounds[i].sound.stop(sounds[i].id);						
					sounds[i].sound = null;
				}
			}
		}
	}
}
 
Example #9
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void put(Sound sound, int channel, float volume, float pitch) {
	this.sound[cpos] = sound;
	this.volume[cpos] = volume;
	this.pitch[cpos] = pitch;
	this.channels[cpos] = channel;
	this.loops[cpos] = false;
	cpos = (cpos + 1) % this.sound.length;
}
 
Example #10
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void put(Sound sound, float volume, boolean loop) {
	this.sound[cpos] = sound;
	this.volume[cpos] = volume;
	this.pitch[cpos] = 0;
	this.channels[cpos] = 0;
	this.loops[cpos] = loop;
	cpos = (cpos + 1) % this.sound.length;
}
 
Example #11
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void stop(Sound snd, int channel) {
	for (int i = 0; i < sound.length; i++) {
		if (sound[i] == snd && this.channels[i] == channel) {
			sound[i].stop(ids[i]);
			sound[i] = null;
		}
	}
}
 
Example #12
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 #13
Source File: Assets.java    From SIFTrain with MIT License 5 votes vote down vote up
public static void queueLoading() {
    internalManager.load("textures/textures.pack.atlas", TextureAtlas.class);
    internalManager.load("hitsounds/bad.mp3", Sound.class);
    internalManager.load("hitsounds/good.mp3", Sound.class);
    internalManager.load("hitsounds/great.mp3", Sound.class);
    internalManager.load("hitsounds/perfect.mp3", Sound.class);
    internalManager.load("bigimages/main_menu_background.jpg", Texture.class);
    internalManager.load("images/hold_background.png", Texture.class);
    internalManager.load("fonts/combo-font.fnt", BitmapFont.class);
    internalManager.load("fonts/song-font.fnt", BitmapFont.class);
    reloadBeatmaps();
}
 
Example #14
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 #15
Source File: Audio.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public boolean play() {
  if (stream) {
    ((Music) delegate).play();
    return true;
  } else {
    id = ((Sound) delegate).play();
    return id != -1;
  }
}
 
Example #16
Source File: Audio.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void stop() {
  if (stream) {
    ((Music) delegate).stop();
  } else {
    ((Sound) delegate).stop(id);
  }
}
 
Example #17
Source File: Audio.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setVolume(float volume) {
  if (stream) {
    ((Music) delegate).setVolume(volume);
  } else {
    ((Sound) delegate).setVolume(id, volume);
  }
}
 
Example #18
Source File: VolumeControlledSoundLoader.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void loadAsync(AssetManager manager, String fileName, FileHandle file,
                      SoundParameter parameter) {
  super.loadAsync(manager, fileName, file, parameter);
  final Sound sound = wrap(getLoadedSound());
  if (controller != null) {
    controller.manage(new WeakReference<>(sound));
  }
}
 
Example #19
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void play(AudioElement<Sound> id, float volume, boolean loop) {
	if(soundthread) {
		mixer.put(id.audio, volume, loop);
	} else {
		synchronized (lock) {
			if(loop) {
				id.id = id.audio.loop(volume);
			} else {
				id.id = id.audio.play(volume);
			}				
		}
	}
}
 
Example #20
Source File: EngineAssetManager.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public Sound getSound(String filename) {
	String n = checkIOSSoundName(SOUND_DIR + filename);

	if (n == null)
		return null;

	return get(n, Sound.class);
}
 
Example #21
Source File: AudioManager.java    From Norii with Apache License 2.0 5 votes vote down vote up
public void dispose(){
    for(Music music: queuedMusic.values()){
        music.dispose();
    }

    for(Sound sound: queuedSounds.values()){
        sound.dispose();
    }
}
 
Example #22
Source File: EngineAssetManager.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void loadSound(String filename) {
	String n = checkIOSSoundName(SOUND_DIR + filename);

	if (n == null)
		return;

	load(n, Sound.class);
}
 
Example #23
Source File: Klooni.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void create() {
    onDesktop = Gdx.app.getType().equals(Application.ApplicationType.Desktop);
    prefs = Gdx.app.getPreferences("dev.lonami.klooni.game");

    // Load the best match for the skin (depending on the device screen dimensions)
    skin = SkinLoader.loadSkin();

    // Use only one instance for the theme, so anyone using it uses the most up-to-date
    Theme.skin = skin; // Not the best idea
    final String themeName = prefs.getString("themeName", "default");
    if (Theme.exists(themeName))
        theme = Theme.getTheme(themeName);
    else
        theme = Theme.getTheme("default");

    Gdx.input.setCatchBackKey(true); // To show the pause menu
    setScreen(new MainMenuScreen(this));
    String effectName = prefs.getString("effectName", "vanish");
    effectSounds = new HashMap<String, Sound>(EFFECTS.length);
    effect = EFFECTS[0];
    for (IEffectFactory e : EFFECTS) {
        loadEffectSound(e.getName());
        if (e.getName().equals(effectName)) {
            effect = e;
        }
    }
}
 
Example #24
Source File: Klooni.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dispose() {
    super.dispose();
    skin.dispose();
    theme.dispose();
    if (effectSounds != null) {
        for (Sound s : effectSounds.values()) {
            s.dispose();
        }
        effectSounds = null;
    }
}
 
Example #25
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Sound getKeySound(Path p) {
	for(Path path : AudioDriver.getPaths(p.toString())) {
		final String filename = path.toString();
		final String name = filename.substring(0, filename.lastIndexOf('.'));
		final String ext = filename.substring(filename.lastIndexOf('.'));
		final Sound sound = getKeySound(name, ext);
		if(sound != null) {
			return sound;
		}
	}
	return null;		
}
 
Example #26
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
private Sound getKeySound(String name, String ext) {
	switch (ext.toLowerCase(Locale.ROOT)) {
		case ".wav":
		case ".flac":
			return getKeySound(new PCMHandleStream(name + ext));
		case ".ogg":
		case ".mp3":
			return getKeySound(Gdx.files.internal(name + ext));
	}
	return null;

}
 
Example #27
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
private Sound getKeySound(FileHandle handle) {
	try {
		return Gdx.audio.newSound(handle);
	} catch (GdxRuntimeException e) {
		Logger.getGlobal().warning("音源ファイル読み込み失敗" + e.getMessage());
	}
	return null;
}
 
Example #28
Source File: GdxSoundDriver.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Sound getKeySound(final PCM pcm) {
	return Gdx.audio.newSound(new FileHandleStream("tempwav.wav") {
		@Override
		public InputStream read() {
			return new WavFileInputStream(pcm);
		}

		@Override
		public OutputStream write(boolean overwrite) {
			return null;
		}
	});
}
 
Example #29
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 #30
Source File: AudioUtils.java    From martianrun with Apache License 2.0 4 votes vote down vote up
public Sound createSound(String soundFileName) {
    return Gdx.audio.newSound(Gdx.files.internal(soundFileName));
}