1
\$\begingroup\$

I am using XNA's SoundEffect class to play sounds. I have to unload all sounds from the corresponding ContentManager for technical reasons, while some of them are still playing.

What happens to sounds that are still playing (via SoundEffect instances) when being unloaded? It seems that they just stop abruptly. Is this a deterministic behaviour I can rely on? Can it cause any errors when unloading sounds that are currently playing?

\$\endgroup\$
  • 1
    \$\begingroup\$ Is there a reason why you don't do things correctly and stop playing all sounds first? What are the "technical reasons"? \$\endgroup\$ – Jim Perry Feb 12 '14 at 13:52
  • \$\begingroup\$ Some sounds I need to play using the Play() method that plays the sound (afaik) creating an instance that I cannot access. Without that instance, I cannot stop the sound once it has been started. \$\endgroup\$ – ares_games Feb 12 '14 at 18:09
1
\$\begingroup\$

When you call Unload() on the ContentManager it will internally call Dispose() on any object that was loaded that implements the IDisposable interface (which SoundEffect does). Therefore yes, it is deterministic that calling Unload() on the ContentManager will stop all SoundEffect instances as they are being disposed.

Shawn Hargreaves wrote a nice blog post about the ContentManager that details the extensibility points of ContentManager while also describing this default behavior.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.