Question

I use a pattern MVVM Caliburn Micro and in my ViewModel I have this code

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)
{
    //...
}

on this microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);

receive error => System.NullReferenceException: Object reference not set to an instance of an object

Was it helpful?

Solution

Is ID_CAP_MICROPHONE capability enabled in WMAppManifest.xml? Microphone.Default returns NULL if this is not enabled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top