Java Code Examples for com.badlogic.gdx.audio.Music#setVolume()
The following examples show how to use
com.badlogic.gdx.audio.Music#setVolume() .
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: SoundManager.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
public void playMusicBeautifully(String name, Stage stage) { final Music music = musics.get(name); if (music == null) { Logger.error("there is no music for " + name); return; } music.setVolume(0); if (!usesMusic) { disabledMusics.add(music); } else { music.play(); } music.setLooping(true); playingMusics.add(music); Action action = new TemporalAction(5f, Interpolation.linear) { @Override protected void update(float percent) { music.setVolume(percent * volume); } }; stage.addAction(action); replaceAction(music, action); }
Example 2
Source File: SoundManager.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
public void stopMusicBeautifully(String name, Stage stage) { final Music music = musics.get(name); if (music == null) { Logger.error("there is no music for " + name); return; } final float initialVolume = music.getVolume(); Action action = new TemporalAction(2f, Interpolation.linear) { @Override protected void update(float percent) { music.setVolume(initialVolume - percent * initialVolume); } @Override protected void end() { music.stop(); playingMusics.remove(music); disabledMusics.remove(music); } }; stage.addAction(action); replaceAction(music, action); }
Example 3
Source File: AudioGdxMusicTest.java From gdx-pd with Apache License 2.0 | 6 votes |
public static void main(String[] args) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); new LwjglApplication(new Game(){ @Override public void create() { // play a music Music music = Gdx.audio.newMusic(Gdx.files.classpath("cloudconnected.ogg")); music.setVolume(0.3f); music.play(); // and a pd patch at the same time Pd.audio.create(new PdConfiguration()); Pd.audio.open(Gdx.files.local("resources/test.pd")); }}, config); }
Example 4
Source File: GameManager.java From Bomberman_libGdx with MIT License | 6 votes |
public void playMusic(String musicName, boolean isLooping) { Music music = assetManager.get(musicPath + musicName); music.setVolume(0.6f); if (currentMusic.equals(musicName)) { music.setLooping(isLooping); if (!music.isPlaying()) { music.play(); } return; } stopMusic(); music.setLooping(isLooping); music.play(); currentMusic = musicName; }
Example 5
Source File: SoundManager.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public void playMusicAsSound(String name) { Music music = musics.get(name); if (music == null) { Logger.error("there is no music for " + name); return; } music.setVolume(volume); music.play(); }
Example 6
Source File: SoundManager.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public void setVolume(float volume) { if (volume < 0) volume = 0; if (volume > 1) volume = 1; this.volume = volume; for (Music music : musics.values()) { music.setVolume(volume); } }
Example 7
Source File: VolumeControlledMusicLoader.java From riiablo with Apache License 2.0 | 5 votes |
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, MusicParameter parameter) { super.loadAsync(manager, fileName, file, parameter); final Music music = getLoadedMusic(); if (controller != null) { music.setVolume(controller.getVolume()); controller.manage(new WeakReference<>(music)); } }
Example 8
Source File: MusicVolumeController.java From riiablo with Apache License 2.0 | 5 votes |
private void refreshVolume() { float volume = getVolume(); for (WeakReference<Music> container : MANAGED) { final Music track = container.get(); if (track == null) { //noinspection SuspiciousMethodCalls MANAGED.remove(track); continue; } track.setVolume(volume); } }
Example 9
Source File: Crossfader.java From SIFTrain with MIT License | 4 votes |
private void initMusic(Music mus) { mus.setLooping(true); mus.setVolume(0.0f); mus.play(); }