0

I have an instrument application that running with XNA Sound Effect. My problem is that; When I play a sound effect while another one is playing, the last one is killing the first one. It is not what I want, I want to play sounds asynchronously even they are the same sounds too. What can I do about it?

Thanks for your help.

  public static SoundEffectInstance passSound;
  public static SoundEffect passSound;


  LoadSoundInstance("Assets/SoundEffects/passSound.wav", out passSound, out passSoundInstance);


  private void LoadSound(String SoundFilePath, out SoundEffect Sound)
    {
        // For error checking, assume we'll fail to load the file.
        Sound = null;

        try
        {
            // Holds informations about a file stream.
            StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));

            // Create the SoundEffect from the Stream
            Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
        }
        catch (NullReferenceException)
        {
            // Display an error message
            MessageBox.Show("Couldn't load sound " + SoundFilePath);
        }
    }

    private void LoadSoundInstance(String SoundFilePath, out SoundEffect Sound, out SoundEffectInstance SoundInstance)
    {
        // For error checking, assume we'll fail to load the file.
        Sound = null;
        SoundInstance = null;

        try
        {
            LoadSound(SoundFilePath, out Sound);
            SoundInstance = Sound.CreateInstance();
        }
        catch (NullReferenceException)
        {
            // Display an error message
            MessageBox.Show("Couldn't load sound instance " + SoundFilePath);
        }
    }

I am using it with only play;

   public void PlaySound(SoundEffectInstance sound)
    {
        sound.Play();
    }

If I call PlaySound method while the same sound is playing it is not play the new one.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
Tugrul Emre Atalay
  • 918
  • 1
  • 9
  • 28

0 Answers0