I'm trying to play SoundEffectInstances of loaded .wav files in my game, but I hear no sound whatsoever.
I have a class "ETSound"; for which each object holds one sound. So one ETSound object might hold the 'menu open' sound, and another might hold the 'tank firing' sound... Etc.
Anyway, the ETSound constructor looks like this:
public ETSound(SoundEffect se, float volume, float pitch, bool looped, int soundPriority) {
soundTemplate = se;
this.volume = volume;
this.pitch = pitch;
this.looped = looped;
if (soundPriority > 0) {
if (soundPriority > 64) soundPriority = 64;
instanceArray = new SoundEffectInstance[soundPriority];
nextInstanceIndex = 0;
for (int i = 0; i < soundPriority; ++i) {
SoundEffectInstance sei = soundTemplate.CreateInstance();
sei.Volume = volume;
sei.Pitch = pitch;
instanceArray[i] = sei;
}
}
}
This basically sets up some parameters, and creates an array of sound effect instances according to the supplied SoundEffect.
Then, I'm calling the Play() function of ETSound:
public void Play() {
if (instanceArray[nextInstanceIndex].State != SoundState.Stopped) instanceArray[nextInstanceIndex].Stop();
instanceArray[nextInstanceIndex].Play();
if (++nextInstanceIndex >= instanceArray.Length) nextInstanceIndex = 0;
}
However, nothing happens. I hear nothing.
Can anyone tell me what's going wrong? Thanks.
Sorry, everyone... Turns out the .wav file I was using to test was corrupt... A tough bug to find, but I got it. Thanks anyway.