Why does this audio setPosition() not work?

Started by Cottonwood, January 22, 2011, 21:55:54

Previous topic - Next topic

Cottonwood

I could abstract the problem to two lines of code:
import java.io.FileInputStream;
import java.io.IOException;
import org.lwjgl.openal.AL;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;

public class JukeOggTester {

	public static boolean positioned;
	private static Audio oggEffect;

	public static void main(String[] args)
	{
		try {oggEffect = AudioLoader.getAudio("OGG",
				new FileInputStream("Barry Ryan - Eloise.ogg"));
		} catch (IOException e) {e.printStackTrace();AL.destroy();return;}
		System.out.println("before setPosition");
		positioned = oggEffect.setPosition(100f);
		System.out.println("after setPosition");
		AL.destroy();
	}

The try... is working. Why dies the setPosition with OpenAL error: Invalid Name (40961)?
Sat Jan 22 22:47:21 CET 2011 INFO:Initialising sounds..
Sat Jan 22 22:47:22 CET 2011 INFO:- Sound works
Sat Jan 22 22:47:22 CET 2011 INFO:- 64 OpenAL source available
Sat Jan 22 22:47:22 CET 2011 INFO:- Sounds source generated
before setPosition
Exception in thread "main" org.lwjgl.openal.OpenALException: OpenAL error: Invalid Name (40961)
	at org.lwjgl.openal.Util.checkALError(Util.java:64)
	at org.lwjgl.openal.AL10.alSourcef(AL10.java:836)
	at org.newdawn.slick.openal.AudioImpl.setPosition(AudioImpl.java:125)
	at de.virginiacity.software.JukeOggTester.main(JukeOggTester.java:20)

Regards. Cottonwood.

hugheth

Hello, I just run in to this problem too, so I'm resurrecting this thread in case anyone else ever runs into the problem

You need to add the line:

if (index == -1) return false;


at the top of the setPosition function of the class org.newdawn.slick.openal.Audio

ending up with:

public boolean setPosition(float position) {
	if (index == -1) return false;
		
	position = position % length;

	AL10.alSourcef(store.getSource(index), AL11.AL_SEC_OFFSET, position);
	if (AL10.alGetError() != 0) {
		return false;
	}
	return true;
}


For some reason the "index" property isn't checked, even in the latest release of Slick2d (I'll comment on their forums asking for a bug fix)