Back to project page Terry-Coin.
The source code is released under:
Apache License
If you think the Android project Terry-Coin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.tcg.terry.managers; // ww w . j a v a 2 s . c om import java.util.HashMap; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.files.FileHandle; public class Content { private HashMap<String, Music> music; private HashMap<String, Sound> sounds; public Content() { music = new HashMap<String, Music>(); sounds = new HashMap<String, Sound>(); } /*********/ /* Music */ /*********/ public void loadMusic(String path) { int slashIndex = path.lastIndexOf('/'); String key; if(slashIndex == -1) { key = path.substring(0, path.lastIndexOf('.')); } else { key = path.substring(slashIndex + 1, path.lastIndexOf('.')); } loadMusic(path, key); } public void loadMusic(String path, String key) { Music m = Gdx.audio.newMusic(Gdx.files.internal(path)); music.put(key, m); } public void loadMusic(FileHandle path, String key) { Music m = Gdx.audio.newMusic(path); music.put(key, m); } public Music getMusic(String key) { return music.get(key); } public void removeMusic(String key) { Music m = music.get(key); if(m != null) { music.remove(key); m.dispose(); } } /*******/ /* SFX */ /*******/ public void loadSound(String path) { int slashIndex = path.lastIndexOf('/'); String key; if(slashIndex == -1) { key = path.substring(0, path.lastIndexOf('.')); } else { key = path.substring(slashIndex + 1, path.lastIndexOf('.')); } loadSound(path, key); } public void loadSound(String path, String key) { Sound sound = Gdx.audio.newSound(Gdx.files.internal(path)); sounds.put(key, sound); } public Sound getSound(String key) { return sounds.get(key); } public void removeSound(String key) { Sound sound = sounds.get(key); if(sound != null) { sounds.remove(key); sound.dispose(); } } /*********/ /* other */ /*********/ public void removeAll() { for(Object o : music.values()) { Music music = (Music) o; music.dispose(); } music.clear(); for(Object o : sounds.values()) { Sound sound = (Sound) o; sound.dispose(); } sounds.clear(); } public void stopAllSound() { for(Object o : music.values()) { Music music = (Music) o; music.stop(); } for(Object o : sounds.values()) { Sound sound = (Sound) o; sound.stop(); } } }