List of usage examples for com.badlogic.gdx.audio Music play
public void play();
From source file:at.therefactory.jewelthief.JewelThief.java
License:Open Source License
/** * Either continues the music playback of a previously paused music file or proceeds to the next music file depending on the proceedToNext flag. * If there was no previous music file, a new music file is chosen randomly. * @param proceedToNext If set to true, a new music file is chosen randomly. If set to false, the previously paused file is being resumed. *//*from w w w .j av a 2 s . c om*/ public void playMusicFile(boolean proceedToNext) { // remember all available music files if (musicFiles == null) { FileHandle dirHandle = Gdx.files.internal("audio/music"); FileHandle[] fileList = dirHandle.list(); musicFiles = new String[fileList.length]; for (int i = 0; i < musicFiles.length; i++) { musicFiles[i] = fileList[i].path(); Gdx.app.log(getClass().getName(), "Found '" + fileList[i].path() + "'"); } } if (musicFiles.length == 0) { Gdx.app.error(getClass().getName(), "Could not find any music files!"); } else { // select a music file to play if (currentMusicFile == -1) { // if there is no previous music file, choose a new one randomly currentMusicFile = (short) Utils.randomWithin(0, musicFiles.length - 1); music = loadMusicAsset(musicFiles[currentMusicFile]); } else if (proceedToNext) { // switch to the next music file randomly int previousMusicFile = currentMusicFile; do { currentMusicFile = (short) Utils.randomWithin(0, musicFiles.length - 1); } while (previousMusicFile == currentMusicFile); assetManager.unload(musicFiles[previousMusicFile]); // free the resources of the previous music file if (music != null) { music.dispose(); music = null; } music = loadMusicAsset(musicFiles[currentMusicFile]); } else { // resume previously paused music file } // play the selected music file music.play(); music.setOnCompletionListener(new Music.OnCompletionListener() { @Override public void onCompletion(Music music) { playMusicFile(true); } }); } }
From source file:com.bagon.matchteam.mtx.managers.AudioManager.java
License:Apache License
/** * Play music, it only plays if SettingsManager.isMusicOn() is true * //w ww . j a v a2 s. co m * @param music * to play * @param isLooping * to loop or not * @param volume * is the volume setting (Range [0.0 - 1.0]) * @see SettingsManager.isMusicOn * * */ public void playMusic(Music music, boolean isLooping, float volume) { if (SettingsManager.isMusicOn()) { music.setLooping(isLooping); music.setVolume(volume); music.play(); } }
From source file:com.davidykay.shootout.ShootOut.java
License:Apache License
@Override public void create() { if (!isInitialized) { screen = new MainMenu(Gdx.app); Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/trollface.ogg", FileType.Internal)); music.setLooping(true);//w w w . j av a 2s. c o m music.play(); isInitialized = true; } }
From source file:com.forerunnergames.peril.client.ui.music.MusicController.java
License:Open Source License
private void startMusicWithFadeIn(final Music music) { music.setVolume(MusicSettings.MIN_VOLUME); music.play(); Timer.schedule(new Timer.Task() { @Override//from w w w . j ava 2 s. c o m public void run() { if (!music.isPlaying()) { cancel(); log.trace("Stopping fading in music [{}] because it isn't playing anymore.", music); return; } final float currentVolume = music.getVolume(); final float delta = masterVolume.getVolume() / MusicSettings.FADE_VOLUME_REPEAT_COUNT; final float newVolume = currentVolume + delta; log.trace("Fading in music [{}] from volume [{}] to volume [{}].", music, currentVolume, newVolume); if (newVolume > masterVolume.getVolume()) { cancel(); log.trace("Done fading in music [{}].", music); return; } music.setVolume(newVolume); } }, 0.0f, MusicSettings.FADE_VOLUME_INTERVAL_SECONDS, MusicSettings.FADE_VOLUME_REPEAT_COUNT); }
From source file:com.gcq.fivesecond.layer.PlayerRoundLayer.java
License:Apache License
@Override public void enter() { PlayerRound.resetXY();/* w w w. j a va2 s. c o m*/ controlRound.resetXY(PlayerRound); addActor(PlayerRound); addActor(controlRound); pointer.setX(310); pointer.setY(50); addActor(pointer); pointer.run(); PlayerRound.addCheck(); director.registerEventHandler(this); GameProperties gp = FiveSecondGame.dbm.getProperties(); if (gp.isAudioOn()) { Music music = musicCache.get(AppMusicDefinitions.MUSIC_GAME_BACKGROUND); music.setLooping(true); music.setVolume(gp.getVolume()); music.play(); } }
From source file:com.jmolina.orb.managers.GameManager.java
License:Open Source License
/** * Crea los temas musicales/*from w ww. jav a2 s . c om*/ */ private void createMusic() { menuMusic = getAsset(Asset.MUSIC_MENU, Music.class); gameMusic = getAsset(Asset.MUSIC_GAME, Music.class); successMusic = getAsset(Asset.MUSIC_SUCCESS, Music.class); menuMusic.setVolume(MUSIC_VOLUME); gameMusic.setVolume(MUSIC_VOLUME); successMusic.setVolume(MUSIC_VOLUME); Music.OnCompletionListener replay = new Music.OnCompletionListener() { @Override public void onCompletion(Music music) { music.play(); } }; menuMusic.setOnCompletionListener(replay); gameMusic.setOnCompletionListener(replay); successMusic.setOnCompletionListener(replay); }
From source file:com.johnogel.astrobros.managers.screens.GameOverScreen.java
@Override public void initialize() { initializeWorld();/* w w w .java 2 s . c om*/ this.updateReferences(); mngr.getSuperManager().getSoundPlayer().initializeLevelSounds(); Music s = mngr.getSuperManager().getSoundPlayer().getSunSound(); s.setLooping(true); s.play(); new PointLight(ray_handler, 5000, Color.RED, 500, -camera.viewportWidth / 2, -300); new PointLight(ray_handler, 5000, Color.RED, 500, camera.viewportWidth / 2, -300); new PointLight(ray_handler, 5000, Color.RED, 500, -camera.viewportWidth / 2, 300); new PointLight(ray_handler, 5000, Color.RED, 500, camera.viewportWidth / 2, 300); }
From source file:com.mangecailloux.pebble.audio.MusicManager.java
License:Apache License
/** * Play the music.//from ww w.j ava 2 s. c o m * @param _key ID of the music. * @param _looping if true, music will loop. */ public void play(String _key, boolean _looping) { Music music = get(_key); if (music != null && !music.isPlaying()) { music.play(); music.setLooping(_looping); } }
From source file:com.maplescot.loggerbill.misc.Assets.java
License:Creative Commons License
/** * Play that funky music, white boy./*from w ww .ja v a2s . c o m*/ * * @param play True to play, else stop. */ public void playMusic(boolean play) { if (!initialized || !assetManager.isLoaded(Constants.MUSIC)) return; // Don't do anything if initialization isn't complete Music music = assetManager.get(MUSIC, Music.class); if (play && !music.isPlaying()) { music.setLooping(true); music.setVolume(0.85f); music.play(); Gdx.app.log(TAG, "Music is playing"); } else if (music.isPlaying() && !play) { Gdx.app.log(TAG, "Stopping music"); music.pause(); } }
From source file:com.mk.apps.superm.mtx.AbstractAssets.java
License:Apache License
/** * Play music, it will only play if SettingsManager.isMusicOn is true * //from ww w.java2 s . c o m * @param music to play * @param isLooping to loop or not * @param volume is the volume setting (Range [0.0 - 1.0]) * @see SettingsManager.isMusicOn * * */ public static void playMusic(Music music, boolean isLooping, float volume) { if (SettingsManager.isMusicOn) { music.setLooping(isLooping); music.setVolume(volume); music.play(); } }