C # XNA: stopping and playing Cue objects (sound)

I try to stop Cue and then play it again. This code is in the Update () loop:

Cue torpedoSound = soundBank.GetCue("torpedo"); torpedoSound.Stop(AudioStopOptions.AsAuthored); torpedoSound.Play(); // Invalid Operation Exception 

However, I always get an InvalidOperationException in the above location. The documentation says this will happen if Play() is called on Cue , for which isPlaying true. But if I call Stop() right away, how can this be?

This works great:

 soundBank.PlayCue("torpedo"); 

Placing a Stop() call right after that allows the sound to play anyway, which surprises me:

 soundBank.PlayCue("torpedo"); torpedoSound.Stop(AudioStopOptions.Immediate); 

Doesn't that make it never audible to the user?

In addition, when the sound is already playing, the Stop() call cannot be stopped.

I am new to C # / XNA.

+4
source share
1 answer

Once Cue is stopped, it can no longer be used. You should get a new Cue instance from the sound engine.

Refer to this sample: http://msdn.microsoft.com/en-us/library/dd940205.aspx

As for stopping, Cue doesn't stop right away when you call Stop. It can take a frame or two, or even more if the final transition is determined.

+2
source

Source: https://habr.com/ru/post/1300262/


All Articles