Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoCaptureElement created runtime fires MediaFailed #83

Open
stevefatsg opened this issue Aug 9, 2018 · 1 comment
Open

VideoCaptureElement created runtime fires MediaFailed #83

stevefatsg opened this issue Aug 9, 2018 · 1 comment

Comments

@stevefatsg
Copy link

stevefatsg commented Aug 9, 2018

When VideoCaptureElement is added in XAML I can correctly show my webcam video.
If, instead, I add it runtime (see following code), after assigning the VideoCaptureDevice property, MediaFailed is fired ("Capture device not found or could not be created")

public partial class MainWindow : Window
{
    WPFMediaKit.DirectShow.Controls.VideoCaptureElement VCE;

    public MainWindow()
    {
        InitializeComponent();

        VCE = new WPFMediaKit.DirectShow.Controls.VideoCaptureElement();
        Content = VCE;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        VCE.MediaOpened += VCE_MediaOpened;
        VCE.MediaFailed += VCE_MediaFailed;
        VCE.VideoCaptureDevice = WPFMediaKit.DirectShow.Controls.MultimediaUtil.VideoInputDevices[0];  // This is my laptop webcam
    }

    void VCE_MediaOpened(Object sender, RoutedEventArgs e) { ... }

    void VCE_MediaFailed(object sender, WPFMediaKit.DirectShow.MediaPlayers.MediaFailedEventArgs e) { ... }
}
@stf1981
Copy link

stf1981 commented Dec 6, 2019

I have the same error. The reason for the error is the property VideoCaptureElement.HasInitialized from the base class MediaElementBase. The property is always false when the VideoCaptureElement is added at Runtime. When these set manuelly to true the Webcam Video are showing as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants