From a30563b4a309e46d925a5cf0b9ad55f1a800de45 Mon Sep 17 00:00:00 2001 From: Luis Gutierrez Date: Wed, 8 May 2013 15:53:38 -0500 Subject: [PATCH] Ejecuta el sonido cuando se le llama --- .../lumpundform/audio/ManejadorDeSonido.java | 125 +++++++++--------- 1 file changed, 62 insertions(+), 63 deletions(-) diff --git a/lumpundform/src/com/lumpundform/audio/ManejadorDeSonido.java b/lumpundform/src/com/lumpundform/audio/ManejadorDeSonido.java index bf25435..500df6d 100644 --- a/lumpundform/src/com/lumpundform/audio/ManejadorDeSonido.java +++ b/lumpundform/src/com/lumpundform/audio/ManejadorDeSonido.java @@ -1,63 +1,62 @@ -package com.lumpundform.audio; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.files.FileHandle; -import com.badlogic.gdx.utils.Disposable; -import com.lumpundform.audio.SonidosDisponibles; -import com.lumpundform.utilerias.LRUCache; -import com.lumpundform.utilerias.LRUCache.CacheEntryRemovedListener; - -public class ManejadorDeSonido implements - CacheEntryRemovedListener, Disposable { - - private float volumen = 1f; - private boolean habilitado = true; - - private final LRUCache cacheSonido; - - public ManejadorDeSonido() { - cacheSonido = new LRUCache(10); - cacheSonido.setEntryRemovedListener(this); - } - - public void play(SonidosDisponibles sonido) { - if (!habilitado) - return; - - Sound sonidoParaReproducir = cacheSonido.get(sonido); - if (sonidoParaReproducir == null) { - FileHandle archivoDeSonido = Gdx.files.internal(sonido - .getNombreArchivo()); - sonidoParaReproducir = Gdx.audio.newSound(archivoDeSonido); - cacheSonido.add(sonido, sonidoParaReproducir); - sonidoParaReproducir.play(volumen); - } - } - - public void ajustarVolumen(float volumen) { - if (volumen < 0 || volumen > 1f) - throw new IllegalArgumentException( - "El volumen debe de estar entre 1 y 0."); - - this.volumen = volumen; - } - - public void habilitado(boolean habilitado) { - this.habilitado = habilitado; - } - - @Override - public void dispose() { - for (Sound sonido : cacheSonido.retrieaveAll()) { - sonido.stop(); - sonido.dispose(); - } - } - - @Override - public void notifyEntryRemoved(SonidosDisponibles key, Sound value) { - value.dispose(); - } - -} +package com.lumpundform.audio; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.Disposable; +import com.lumpundform.audio.SonidosDisponibles; +import com.lumpundform.utilerias.LRUCache; +import com.lumpundform.utilerias.LRUCache.CacheEntryRemovedListener; + +public class ManejadorDeSonido implements + CacheEntryRemovedListener, Disposable { + + private float volumen = 1f; + private boolean habilitado = true; + + private final LRUCache cacheSonido; + + public ManejadorDeSonido() { + cacheSonido = new LRUCache(10); + cacheSonido.setEntryRemovedListener(this); + } + + public void play(SonidosDisponibles sonido) { + if (!habilitado) + return; + Sound sonidoParaReproducir = cacheSonido.get(sonido); + if (sonidoParaReproducir == null) { + FileHandle archivoDeSonido = Gdx.files.internal(sonido + .getNombreArchivo()); + sonidoParaReproducir = Gdx.audio.newSound(archivoDeSonido); + cacheSonido.add(sonido, sonidoParaReproducir); + } + sonidoParaReproducir.play(volumen); + } + + public void ajustarVolumen(float volumen) { + if (volumen < 0 || volumen > 1f) + throw new IllegalArgumentException( + "El volumen debe de estar entre 1 y 0."); + + this.volumen = volumen; + } + + public void habilitado(boolean habilitado) { + this.habilitado = habilitado; + } + + @Override + public void dispose() { + for (Sound sonido : cacheSonido.retrieaveAll()) { + sonido.stop(); + sonido.dispose(); + } + } + + @Override + public void notifyEntryRemoved(SonidosDisponibles key, Sound value) { + value.dispose(); + } + +}