com.badlogic.gdx.audio.Music Java Examples
The following examples show how to use
com.badlogic.gdx.audio.Music.
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 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 #2
Source File: AssetsManagerGDX.java From Entitas-Java with MIT License | 6 votes |
@Override public void playMusic(String name) { if (!preferencesManager.MUSIC) { stopMusic(); return; } stopMusic(); if (assetManager.isLoaded(name, Music.class)) currentMusicPlaying = assetManager.get(name, Music.class); loadAsset(name, Music.class); assetManager.finishLoading(); if (currentMusicPlaying != null) { currentMusicPlaying.play(); currentMusicPlaying.setLooping(true); currentMusicPlaying.setVolume(preferencesManager.VOL_MUSIC); } }
Example #3
Source File: MusicController.java From riiablo with Apache License 2.0 | 6 votes |
public void next() { stop(); if (PLAYLIST.isEmpty()) { return; } this.asset = PLAYLIST.removeFirst(); ASSETS.load(asset, Music.class); ASSETS.finishLoadingAsset(asset); this.track = ASSETS.get(asset, Music.class); track.setOnCompletionListener(this); track.play(); if (Gdx.app.getLogLevel() >= Application.LOG_DEBUG) { Gdx.app.debug(TAG, "Now playing \"" + asset + "\""); } }
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: 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 #6
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 #7
Source File: AudioManager.java From Norii with Apache License 2.0 | 6 votes |
private Music playMusic(boolean isLooping, String fullFilePath){ Music music = queuedMusic.get(fullFilePath); if( music != null ){ music.setLooping(isLooping); music.play(); }else if(Utility.isAssetLoaded(fullFilePath)){ music = Utility.getMusicAsset(fullFilePath); music.setLooping(isLooping); music.play(); queuedMusic.put(fullFilePath, music); }else{ Gdx.app.debug(TAG, "Music not loaded"); return null; } return music; }
Example #8
Source File: GdxAudioRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void playSourceInstance(AudioNode audioNode) { Gdx.app.log("GdxAudioRenderer", "playSourceInstance"); GdxAudioData audioData; audioData = (GdxAudioData) audioNode.getAudioData(); Music music = musicMap.get(audioNode); if (Gdx.app.getType() == Application.ApplicationType.iOS && audioData.getAssetKey().getName().endsWith(".ogg")) { return; } if (music == null) { music = Gdx.audio.newMusic(GdxAssetCache.getFileHandle(audioData.getAssetKey().getName())); musicMap.put(audioNode, music); } music.stop(); music.play(); audioNode.setStatus(AudioNode.Status.Playing); }
Example #9
Source File: GdxAudioRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void update(float v) { // Gdx.app.log("GdxAudioRenderer", "update"); for(AudioNode src : musicMap.keySet()) { Music music = musicMap.get(src); if (src.getStatus() == AudioNode.Status.Playing) { if (!music.isPlaying()) { Gdx.app.log("GdxAudioRenderer","music Stopped"); src.setStatus(AudioNode.Status.Stopped); } else { } } } }
Example #10
Source File: GdxAudioRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void cleanup() { Gdx.app.log("GdxAudioRenderer", "cleanup"); for(Music music : musicMap.values()) { music.dispose(); } musicMap.clear(); }
Example #11
Source File: Audio.java From riiablo with Apache License 2.0 | 5 votes |
static Instance obtain(AssetDescriptor descriptor, Object delegate, long id) { Instance instance = Pools.obtain(Instance.class); instance.descriptor = descriptor; instance.stream = delegate instanceof Music; instance.delegate = delegate; instance.id = id; return instance; }
Example #12
Source File: Audio.java From riiablo with Apache License 2.0 | 5 votes |
public void stop() { if (stream) { ((Music) delegate).stop(); } else { ((Sound) delegate).stop(id); } }
Example #13
Source File: Audio.java From riiablo with Apache License 2.0 | 5 votes |
public void setVolume(float volume) { if (stream) { ((Music) delegate).setVolume(volume); } else { ((Sound) delegate).setVolume(id, volume); } }
Example #14
Source File: MusicController.java From riiablo with Apache License 2.0 | 5 votes |
public void stop() { final Music track = this.track; if (track == null) { return; } // assert asset != null; if (ASSETS.isLoaded(asset)) ASSETS.unload(asset); track.dispose(); }
Example #15
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 #16
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 #17
Source File: EngineAssetManager.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public Music getMusic(String filename) { String n = checkIOSSoundName(MUSIC_DIR + filename); if (n == null) return null; return get(n, Music.class); }
Example #18
Source File: GameManager.java From Bomberman_libGdx with MIT License | 5 votes |
public void playMusic() { if (currentMusic.isEmpty()) { return; } Music music = assetManager.get(musicPath + currentMusic, Music.class); music.play(); }
Example #19
Source File: Audio.java From riiablo with Apache License 2.0 | 5 votes |
public boolean play() { if (stream) { ((Music) delegate).play(); return true; } else { id = ((Sound) delegate).play(); return id != -1; } }
Example #20
Source File: GameManager.java From Bomberman_libGdx with MIT License | 5 votes |
public void stopMusic() { if (currentMusic.isEmpty()) { return; } Music music = assetManager.get(musicPath + currentMusic, Music.class); if (music.isPlaying()) { music.stop(); } }
Example #21
Source File: MusicState.java From gdx-soundboard with MIT License | 5 votes |
@Override public void onCompletion(Music music) { if (!loopTrack) { if (randomTrack) { currentTrackIndex = MathUtils.random(0, tracks.size - 1); } else { currentTrackIndex = (currentTrackIndex + 1) % tracks.size; } } Track currentTrack = getCurrentTrack(); if(currentTrack != null){ currentTrack.reset(); currentTrack.play(); } }
Example #22
Source File: GameManager.java From Bomberman_libGdx with MIT License | 5 votes |
public void pauseMusic() { if (currentMusic.isEmpty()) { return; } Music music = assetManager.get(musicPath + currentMusic, Music.class); if (music.isPlaying()) { music.pause(); } }
Example #23
Source File: VoiceManager.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@Override public void loadAssets() { if (voice == null && fileName != null) { EngineLogger.debug("LOADING VOICE: " + fileName); EngineAssetManager.getInstance().load(EngineAssetManager.VOICE_DIR + fileName, Music.class); } }
Example #24
Source File: VoiceManager.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@Override public void retrieveAssets() { if (voice == null && fileName != null) { EngineLogger.debug("RETRIEVING VOICE: " + fileName); voice = EngineAssetManager.getInstance().get(EngineAssetManager.VOICE_DIR + fileName, Music.class); voice.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(Music music) { if (textManager.getCurrentText() != null) textManager.getCurrentText().setAutoTime(); } }); if (voice != null) voice.setVolume(volume * VOLUME_MULTIPLIER); if (isPlayingSer) { voice.play(); if (voice != null) { voice.setPosition(voicePosSer); } isPlayingSer = false; voicePosSer = 0f; } } }
Example #25
Source File: SongSelectionScreen.java From SIFTrain with MIT License | 5 votes |
private void updatePreviewSong() { if(Assets.selectedGroup == null) return; Music previewMusic = null; String musicFile = Assets.selectedGroup.music_file; if(musicFile != null) previewMusic = SongLoader.loadSongByName(musicFile); if(previewMusic == null) previewMusic = SongLoader.loadSongByName(Assets.selectedGroup.resource_name); previewCrossfader.enqueue(previewMusic); }
Example #26
Source File: AudioManager.java From Norii with Apache License 2.0 | 5 votes |
public void dispose(){ for(Music music: queuedMusic.values()){ music.dispose(); } for(Sound sound: queuedSounds.values()){ sound.dispose(); } }
Example #27
Source File: Crossfader.java From SIFTrain with MIT License | 5 votes |
public void enqueue(Music mus) { disposeOf(enqueued); enqueued = mus; enqueuedStop = (mus == null); if(fadingOut == null) fadeIn(); }
Example #28
Source File: Crossfader.java From SIFTrain with MIT License | 5 votes |
private void disposeOf(Music mus) { if(mus == null) return;; if(mus.isPlaying()) mus.stop(); mus.dispose(); }
Example #29
Source File: WorldController.java From SIFTrain with MIT License | 5 votes |
@Override public void onCompletion(Music music) { if (isABRepeatMode && !done) { resetMarks(); if (hasMusic) { theSong.pause(); theSong.setPosition(aPosition); theSong.play(); lastmtime = theSong.getPosition(); time = lastmtime + world.delay; timeSyncAcc = 0; } else { time = aPosition; } return; } if (hasMusic) { music.dispose(); } done = true; if (this.largestCombo < this.combo) { this.largestCombo = combo; } Results.bads = badCount; Results.goods = goodCount; Results.greats = greatCount; Results.perfects = perfectCount; Results.miss = missCount; Results.combo = largestCombo; Results.accuracy = calculateAccuracy(); Results.normalizedAccuracy = calculateNormalizedAccuracy(); accuracyMarkers.clear(); accuracyPopups.clear(); marks.clear(); tapZones.clear(); ((Game) Gdx.app.getApplicationListener()).setScreen(new ResultsScreen()); }
Example #30
Source File: SongLoader.java From SIFTrain with MIT License | 5 votes |
public static Music loadSongFile() { Music result = null; if(Assets.selectedSong.music_file != null) result = loadSongByName(Assets.selectedSong.music_file); if(result == null) result = loadSongByName(Assets.selectedSong.getResourceName()); return result; }