简体   繁体   English

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

[英]Is there a way to stop a SoundEffect audio playback?

I am using the following code snippet to play .wav files: 我正在使用以下代码片段播放.wav文件:

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

Is there a way to stop the sound after it starts playing? 开始播放后是否有停止声音的方法?

Create a SoundEffectInstance from your SoundEffect then you'll have access to more actions to control your sound. 从您的SoundEffect创建一个SoundEffectInstance ,然后您将可以使用更多操作来控制声音。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM