有没有办法停止SoundEffect音频播放?

时间:2013-05-29 00:42:33

标签: c# windows-phone-7

我使用以下代码段来播放.wav文件:

Stream s = TitleContainer.OpenStream("sounds/MySound.wav");
SoundEffect effect = SoundEffect.FromStream(s);
FrameworkDispatcher.Update();
effect.Play();

有没有办法在开始播放后停止声音?

1 个答案:

答案 0 :(得分:0)

SoundEffectInstance创建SoundEffect,然后您就可以访问更多操作来控制声音了。

Stream s = TitleContainer.OpenStream("sounds/MySound.wav");
SoundEffect effect = SoundEffect.FromStream(s);
var effectInstance = effect.CreateInstance();
FrameworkDispatcher.Update();
effectInstance.Play();

// This will stop the sound
effectInstance.Stop();