AudioNode: Play vs PlayInstance

When you call audioNode.playInstance() there is no way to stop or adjust any paramaters of the sound, and after looking at the javadoc this seems to be the intended functionality.

Is there any easy way to access a list of the instances of the audio that get played when you call playInstance()? I briefly looked at the source code but don’t see a straightforward way to get a specific audio instance from the renderer, and don’t have much experience with this area of the source code.

If it is not possible to get an audio instance, then it seems like there would never be a viable reason to use playInstance() in place of play() if you ever want to have a game with pausing or a sound options menu where you can turn down the volume of sounds that are currently playing and have the results immediately take effect when you resume. This seems important when I think back to the days of being a kid playing games at night, when a loud explosion would happen and I’d quickly pause to turn down the effects volume slider in the menu so I wouldn’t wake everyone up. It would be annoying to un-pause only to hear the explosion still going at full volume lol.

I looked at the Hello Audio tutorial and I see it uses .play() for ambient sounds and uses .playInstance() for a gun shot sound. So I’m guessing the idea was that the gun shot should be short enough and that would make it okay to have an un-editable sound instance, but this is still potentially problematic because even a sound effect like a gunshot that lasts half a second could still be interrupted by the pause screen multiple times before the sound finishes.

1 Like

waking mom up really gives new perspective on Game OVER :smiling_face_with_tear:

1 Like

play() is for managing a sound over time, etc… The node = a sound. You can control it, play it, pause it, stop it, etc…

playInstance() is for short one-off sounds that are quicked and unmanaged. They adopt whatever settings of the audio node at the time playInstance() is called. Bang, bang, bang, bang, bang… where one audio node can produce 5 bangs that might overlap. They are unmanaged. Fire and forget.

If you pause in the middle of playInstance() then it will still finish playing… but the sound should be super short anyway and it won’t matter. If the pause button made a “click” sound then that will be longer than the last “bang” anyway.

For quick sounds, especially if you will slightly randomize the frequency, playInstance() will be easier to deal with than creating, managing, and destroying hundreds of audio nodes.