Playing the same AudioNode while it's already playing?

I noticed you can’t play the same audio node while it’s already playing. Short a creating a new node, would there be a way to do this? Like playing the same node on a different channel instead? I would do this but since there’s a note saying not to use those in the javadoc, I’m not sure I should fiddle with that.

For my sound effects library I decided to use them this way:

[java]notification = new AudioNode(assetManager, NOTIFICATION);[/java]

So, when I call the method to play it, while it’s already playing, the second time is simply ignored.:

[java] @Override
public void notification() {
// ar = AudioRenderer.


Although you have to have exactly the same settings on both instances…

1 Like

The channel methods are called by the audio renderer thread to store its own data. That’s why you should not call them.

Other than the playInstanced() thing, which will play the sound with whatever settings it has when the sound is played, you have to make a new node. Usually playInstanced() is enough. All of the sounds don’t have to have the same settings but you can’t change the playing sound’s properties after playInstance() is called. You can, however, change the settings and playInstance() another sound.

If you are forward thinking, I would steer away from playInstance() since it gives you no control over the sound once started. I opted for a sound manager so that I might one day prioritize sounds. Only so many can play at a time and maybe someday I get to the point where all of the channels are being used by random events in the game and I still want a sound to override them. At least now I have the data structures to do it even if the code isn’t there.

Thanks for the input guys. Much appreciated.

I’ll make some tests in the morning and get back to you. :slight_smile:

playInstanced() seems to do the trick without ill effect.

Thanks. :smiley: