/// <summary> /// Triggered when webcam feed loads both for the first time and every time this page is navigated to. /// If no WebcamHelper has been created, it creates one. Otherwise, simply restarts webcam preview feed on page. /// </summary> private async void WebcamFeed_Loaded(object sender, RoutedEventArgs e) { if (webcam == null || !webcam.IsInitialized()) { // Initialize Webcam Helper webcam = new WebcamHelper(); await webcam.InitializeCameraAsync(); // Set source of WebcamFeed on MainPage.xaml WebcamFeed.Source = webcam.mediaCapture; // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached. if (WebcamFeed.Source != null) { // Start the live feed await webcam.StartCameraPreview(); } } else if (webcam.IsInitialized()) { WebcamFeed.Source = webcam.mediaCapture; // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached. if (WebcamFeed.Source != null) { await webcam.StartCameraPreview(); } } }
/// <summary> /// Triggered when the webcam feed control is loaded. Sets up the live webcam feed. /// </summary> private async void WebcamFeed_Loaded(object sender, RoutedEventArgs e) { WebcamFeed.Source = webcam.mediaCapture; // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached. if (WebcamFeed.Source != null) { await webcam.StartCameraPreview(); } }