Caliburn Micro和Microphone NullReferenceException

时间:2014-05-12 09:49:14

标签: windows-phone-8 mvvm caliburn.micro caliburn

我使用模式MVVM Caliburn Micro,在我的ViewModel中我有这个代码

private Microphone microphone;
private byte[] buffer;
private MemoryStream stream;

public MainViewModel()
{
    microphone = Microphone.Default;
    stream = new MemoryStream();

    DispatcherTimer dt = new DispatcherTimer();
    dt.Interval = TimeSpan.FromMilliseconds(50);
    dt.Tick += delegate
    {
        try
        {
            FrameworkDispatcher.Update();
        }
        catch { }
    };

    dt.Start();
    microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
}

void microphone_BufferReady(object sender, EventArgs e)
{
    //...
}

就此而言 microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);

收到错误=&gt; System.NullReferenceException:未将对象引用设置为对象的实例

1 个答案:

答案 0 :(得分:3)

WMAppManifest.xml是否启用了ID_CAP_MICROPHONE功能?如果未启用, Microphone.Default 将返回NULL。