Capture Device not found or Could not be created

Apr 30, 2013 at 3:29 PM
Edited Apr 30, 2013 at 3:29 PM
Hi,


I want to add VideoCaptureElement during runtime in one of my applications,
and I have tried it using the below code

WPFMediaKit.DirectShow.Controls.VideoCaptureElement videoElement = new WPFMediaKit.DirectShow.Controls.VideoCaptureElement();
videoElement.Width = 320;
videoElement.DesiredPixelWidth = 320;
videoElement.Height = 240;
videoElement.DesiredPixelHeight = 240;
videoElement.VideoCaptureDevice = WPFMediaKit.DirectShow.Controls.MultimediaUtil.VideoInputDevices[0];
videoElement.VideoCaptureSource = WPFMediaKit.DirectShow.Controls.MultimediaUtil.VideoInputDevices[0].Name;
videoElement.MediaFailed += new EventHandler<WPFMediaKit.DirectShow.MediaPlayers.MediaFailedEventArgs>(videoElement_MediaFailed);
gridElement.Children.Add(videoElement);
But when I run the code I get the following error in the MediaFailed Event.
System.Exception: Capture Device not found or could not be created at WPFMediaKit.DirectShow.MediaPlayers.VideoCapturePlayer.SetUpGraph()
But if I do this by adding a VideoCaptureElement in the xaml page and then assign VideoCaptureDevice and VideoCaptureSource it works fine.

So could anyone please give me a proper solution for adding a VideoCaptureElement from Code behind.