我有一个使用 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 方法,则不会播放新声音。