我有一个使用XNA Sound Effect运行的乐器应用程序。我的问题是; 当我播放另一个正在播放的声音效果时,最后一个正在杀死第一个声音效果。这不是我想要的,我想异步播放声音,即使它们也是同样的声音。我该怎么办呢?
感谢您的帮助。
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);
}
}
我只在玩游戏时使用它;
public void PlaySound(SoundEffectInstance sound)
{
sound.Play();
}
如果我在播放相同的声音时调用PlaySound方法,则不会播放新的声音。