我尝试在windows phone app中播放音频缓冲区。
byte[] buffer = new byte[44100 * 2 * 5];
float t = 0;
for (int i = 0; i < 44100 * 2 * 5; i += 2)
{
short val = (short)(Math.Sin(t * 2 * Math.PI * 440) * short.MaxValue);
buffer[i] = (byte)(val & 0xFF);
buffer[i + 1] = (byte)(val >> 8);
t += 1 / 44100.0f;
}
sf = new SoundEffect(buffer, 44100, AudioChannels.Mono);
// Play.
sf.Play();
我收到错误: 类型&#39; System.InvalidOperationException&#39;的第一次机会异常发生在Microsoft.Xna.Framework.ni.dll中 类型&#39; System.InvalidOperationException&#39;的例外情况发生在Microsoft.Xna.Framework.ni.dll但未在用户代码中处理
帮忙吧!
答案 0 :(得分:0)
您需要致电FrameworkDispatcher.Update
。
这里的答案应该有效: Playing a sound from a generated buffer in a Windows phone app