我对 windows phone 抖动库有问题。我构建了一个应用程序,它的震动声音会消失,它的工作很好,但奇怪的错误让我感到困惑。我有两页。这是我的单独代码:
void Instance_ShakeGesture1(object sender, ShakeGestureEventArgs e)
{
Stream stream = TitleContainer.OpenStream("Sounds/C.wav");
effect = SoundEffect.FromStream(stream);
effectInstance = effect.CreateInstance();
if (effectInstance.State != SoundState.Playing || effectInstance == null)
{
FrameworkDispatcher.Update();
effectInstance.Play();
}
else if (effectInstance.State == SoundState.Playing || effectInstance != null)
{
effectInstance.Stop();
}
}
void Instance_ShakeGesture2(object sender, ShakeGestureEventArgs e)
{
Stream stream = TitleContainer.OpenStream("Sounds/D.wav");
effect = SoundEffect.FromStream(stream);
effectInstance = effect.CreateInstance();
FrameworkDispatcher.Update();
if (effectInstance.State == SoundState.Stopped || effectInstance == null)
{
effectInstance.Play();
}
else if (effectInstance.State == SoundState.Playing || effectInstance != null)
{
effectInstance.Stop();
}
}
Instance_ShakeGesture1 是我在第 1 页摇动时播放音乐的程序,在第 2 页摇动时播放音乐首先是 Instance_ShakeGesture1,然后是 Instance_ShakeGesture2。当我尝试先摇动第 2 页而不是第 1 页时,问题同样出现,Instance_ShakeGesture2 将首先执行,Instance_ShakeGesture2 将在第二个执行。当我使用断点时,我知道这个错误。有谁知道如何解决这个问题?谢谢之前:)