diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java b/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java index 3de484f..ca2e093 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java @@ -14,35 +14,72 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.assets.loaders.FileHandleResolver; +import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; import de.pottgames.tuningfork.Audio; import de.pottgames.tuningfork.SoundBuffer; +import de.pottgames.tuningfork.SoundBufferLoader; +import de.pottgames.tuningfork.SoundBufferLoader.SoundBufferLoaderParameter; +import de.pottgames.tuningfork.SoundSource; import de.pottgames.tuningfork.WaveLoader; public class PlayReverseExample extends ApplicationAdapter { - private Audio audio; - private SoundBuffer sound; + private boolean jobDone = false; + private AssetManager assetManager; + private Audio audio; + private SoundBuffer sound; + private SoundBuffer asyncLoadedSound; + private SoundSource source; @Override public void create() { this.audio = Audio.init(); + this.setupAssetManager(); + this.load(); + this.loadAsync(); + this.source = this.audio.obtainSource(this.sound); + this.source.play(); + } + + + public void setupAssetManager() { + this.assetManager = new AssetManager(); + final FileHandleResolver resolver = new InternalFileHandleResolver(); + this.assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver)); + } + + + public void load() { // use any of these + // this.sound = AiffLoader.loadReverse(Gdx.files.internal("numbers.aiff")); // this.sound = FlacLoader.loadReverse(Gdx.files.internal("numbers_16bit_stereo.flac")); // this.sound = Mp3Loader.loadReverse(Gdx.files.internal("numbers.mp3")); // this.sound = OggLoader.loadReverse(Gdx.files.internal("numbers2.ogg")); this.sound = WaveLoader.loadReverse(Gdx.files.internal("numbers.wav")); - this.sound.play(); + } + + + private void loadAsync() { + final SoundBufferLoaderParameter parameter = new SoundBufferLoaderParameter(); + parameter.reverse = true; + this.assetManager.load("carnivalrides.ogg", SoundBuffer.class, parameter); } @Override public void render() { - // we chill in a black window + if (!this.jobDone && this.assetManager.update() && !this.source.isPlaying()) { + this.asyncLoadedSound = this.assetManager.get("carnivalrides.ogg"); + this.asyncLoadedSound.play(); + this.jobDone = true; + } }