麦克风缓冲区就绪事件处理程序无法进入Windows Phone 8应用程序

时间:2013-06-29 18:28:20

标签: c# windows-phone-8

我在Windows Phone 8 App中有以下代码:

        FrameworkDispatcher.Update();
        microphone = Microphone.Default;
        microphone.BufferReady += Device_BufferReady;
        bStarted = true;
        tbData.Text = "00:00:00";
        m_lDuration = 0;
        microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
        baBuffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
        microphone.Start();

然而,Device_BufferReady永远不会被击中!知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

开发中心(http://code.msdn.microsoft.com/wpapps/Microphone-Sample-b2ebe8b6)上提供的示例代码使用了一个周期为33毫秒的自动收录器,您可以从中调用FrameworkDispatcher.Update()方法......

        // Timer to simulate the XNA Framework game loop (Microphone is 
        // from the XNA Framework). We also use this timer to monitor the 
        // state of audio playback so we can update the UI appropriately.
        DispatcherTimer dt = new DispatcherTimer();
        dt.Interval = TimeSpan.FromMilliseconds(33);
        dt.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };
        dt.Start();

你实现了吗?