gpt4 book ai didi

windows-phone-7 - wp8 Soundeffect无法停止

转载 作者:行者123 更新时间:2023-12-03 02:16:59 25 4
gpt4 key购买 nike

我使用soundeffect播放字节数组中的声音,然后一切正常,但是我无法停止播放声音,因为Soundeffect中没有所谓的stop()方法,我该如何停止它?

编码:

private void playFile(byte[] file)
{
try
{

if (file == null || file.Length == 0) return;


SoundEffect se = new SoundEffect(file, microphone.SampleRate, AudioChannels.Mono);
SoundEffect.MasterVolume = 0.7f;
if (stop != 1)
{
FrameworkDispatcher.Update();
se.Play();
}
else
{
//Here should stop, how !
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}

最佳答案

您是否尝试过在.Dispose()对象上调用SoundEffect?根据documentation

When a SoundEffect object is destroyed, all SoundEffectInstance objects previously created by that SoundEffect will stop playing and become invalid.



此外,除非使用XNA Game Studio 4.0开发,否则请使用 MediaElement代替 Microsoft recommends。因此,如果这适用于您,您可能要考虑使用确实具有 Play, Pause, and Stop functionsMediaElement

关于windows-phone-7 - wp8 Soundeffect无法停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18984378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com