From c2f6ba872805f25f968697c47962861745330d43 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 13 Dec 2010 07:57:40 +0100 Subject: Playing audio again - test: use jar file joal-test.jar - test: use proper getResourceAsStream() on class instance - test: plays sound TODO: - check on windows and osx - add jnlp file template - joal-demos --- src/test/com/jogamp/openal/test/junit/ALTest.java | 5 +---- .../com/jogamp/openal/test/manual/OpenALTest.java | 5 +++-- .../com/jogamp/openal/test/manual/Sound3DTest.java | 2 +- .../openal/test/resources/ResourceLocation.java | 26 ++++++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/test/com/jogamp/openal/test/junit/ALTest.java b/src/test/com/jogamp/openal/test/junit/ALTest.java index 6a465f2..33d7b0d 100644 --- a/src/test/com/jogamp/openal/test/junit/ALTest.java +++ b/src/test/com/jogamp/openal/test/junit/ALTest.java @@ -382,10 +382,7 @@ public class ALTest { } private WAVData loadTestWAV() throws IOException, UnsupportedAudioFileException { - InputStream resource = ResourceLocation.class.getResourceAsStream(TEST_FILE); - if(resource == null) { - throw new FileNotFoundException(TEST_FILE+" not found"); - } + InputStream resource = ResourceLocation.getInputStream(TEST_FILE, true); return WAVLoader.loadFromStream(resource); } } diff --git a/src/test/com/jogamp/openal/test/manual/OpenALTest.java b/src/test/com/jogamp/openal/test/manual/OpenALTest.java index 98843c7..abd335c 100644 --- a/src/test/com/jogamp/openal/test/manual/OpenALTest.java +++ b/src/test/com/jogamp/openal/test/manual/OpenALTest.java @@ -42,7 +42,9 @@ import java.io.IOException; import java.nio.*; import com.jogamp.openal.eax.*; +import com.jogamp.openal.test.resources.ResourceLocation; import com.jogamp.openal.util.*; +import java.io.InputStream; import javax.sound.sampled.UnsupportedAudioFileException; /** @@ -50,7 +52,6 @@ import javax.sound.sampled.UnsupportedAudioFileException; * @author Michael Bien */ public class OpenALTest { - public static void main(String[] args) throws InterruptedException, UnsupportedAudioFileException, IOException { ALC alc = ALFactory.getALC(); ALCdevice device = alc.alcOpenDevice(null); @@ -76,7 +77,7 @@ public class OpenALTest { int[] buffers = new int[1]; al.alGenBuffers(1, buffers, 0); - WAVData wd = WAVLoader.loadFromStream(OpenALTest.class.getResourceAsStream("lewiscarroll.wav")); + WAVData wd = WAVLoader.loadFromStream(ResourceLocation.getTestStream0()); al.alBufferData(buffers[0], wd.format, wd.data, wd.size, wd.freq); int[] sources = new int[1]; diff --git a/src/test/com/jogamp/openal/test/manual/Sound3DTest.java b/src/test/com/jogamp/openal/test/manual/Sound3DTest.java index d91f0ec..55bf28a 100644 --- a/src/test/com/jogamp/openal/test/manual/Sound3DTest.java +++ b/src/test/com/jogamp/openal/test/manual/Sound3DTest.java @@ -63,7 +63,7 @@ public class Sound3DTest { listener.setPosition(0, 0, 0); // load a source and play it - Source source1 = AudioSystem3D.loadSource(ResourceLocation.class.getResourceAsStream("lewiscarroll.wav")); + Source source1 = AudioSystem3D.loadSource(ResourceLocation.getTestStream0()); source1.setPosition(0, 0, 0); source1.setLooping(true); source1.play(); diff --git a/src/test/com/jogamp/openal/test/resources/ResourceLocation.java b/src/test/com/jogamp/openal/test/resources/ResourceLocation.java index 74f1356..f223644 100644 --- a/src/test/com/jogamp/openal/test/resources/ResourceLocation.java +++ b/src/test/com/jogamp/openal/test/resources/ResourceLocation.java @@ -1,6 +1,32 @@ package com.jogamp.openal.test.resources; +import java.io.InputStream; + /** just a tag to locate the resources */ public class ResourceLocation { + public static final String lewiscarrol_wav = "lewiscarroll.wav"; + + static final ResourceLocation rl; + + static { + rl = new ResourceLocation(); + + } + + public static InputStream getTestStream0() { + return getInputStream(lewiscarrol_wav, true); + } + + public static InputStream getInputStream(String fileName) { + return getInputStream(fileName, false); + } + + public static InputStream getInputStream(String fileName, boolean throwException) { + InputStream stream = rl.getClass().getResourceAsStream(fileName); + if(throwException && null == stream) { + throw new RuntimeException("File '"+fileName+"' not found"); + } + return stream; + } } -- cgit v1.2.3