/// <summary> /// Finds the video profile for the front and back camera and queries if /// both cameras have a matching video recording profile that supports concurrency. /// If a matching concurrent profile is supported, then we configure media initialization /// settings for both cameras to the matching profile. /// </summary> /// <param name="sender">Contains information regarding button that fired event</param> /// <param name="e">Contains state information and event data associated with the event</param> private async void CheckConcurrentProfileBtn_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Initialize our concurrency support flag. bool concurrencySupported = false; string frontVideoDeviceId = string.Empty; string backVideoDeviceId = string.Empty; MediaCapture mediaCaptureFront = new MediaCapture(); MediaCapture mediaCaptureBack = new MediaCapture(); // Find front and back Device Id of capture device that supports Video Profile await LogStatusToOutputBox("Looking for all video capture devices on front panel"); frontVideoDeviceId = await GetVideoProfileSupportedDeviceIdAsync(Windows.Devices.Enumeration.Panel.Front); await LogStatusToOutputBox("Looking for all video capture devices on back panel"); backVideoDeviceId = await GetVideoProfileSupportedDeviceIdAsync(Windows.Devices.Enumeration.Panel.Back); // First check if the devices support video profiles, if not there's no reason to proceed if (string.IsNullOrEmpty(frontVideoDeviceId) || string.IsNullOrEmpty(backVideoDeviceId)) { await LogStatus("ERROR: A capture device doesn't support Video Profile", NotifyType.ErrorMessage); return; } await LogStatusToOutputBox("Video Profiles are supported on both cameras"); // Create MediaCaptureInitilization settings for each video capture device MediaCaptureInitializationSettings mediaInitSettingsFront = new MediaCaptureInitializationSettings(); MediaCaptureInitializationSettings mediaInitSettingsBack = new MediaCaptureInitializationSettings(); mediaInitSettingsFront.VideoDeviceId = frontVideoDeviceId; mediaInitSettingsBack.VideoDeviceId = backVideoDeviceId; await LogStatusToOutputBox(string.Format(CultureInfo.InvariantCulture, "Front Device Id located: {0}", frontVideoDeviceId.ToString())); await LogStatusToOutputBox(string.Format(CultureInfo.InvariantCulture, "Back Device Id located: {0}", backVideoDeviceId.ToString())); await LogStatusToOutputBox("Querying for concurrent profile"); // Acquire concurrent profiles available to front and back capture devices, then locate a concurrent // profile Id that matches for both devices var concurrentProfile = (from frontProfile in MediaCapture.FindConcurrentProfiles(frontVideoDeviceId) from backProfile in MediaCapture.FindConcurrentProfiles(backVideoDeviceId) where frontProfile.Id == backProfile.Id select new { frontProfile, backProfile }).FirstOrDefault(); if (concurrentProfile != null) { mediaInitSettingsFront.VideoProfile = concurrentProfile.frontProfile; mediaInitSettingsBack.VideoProfile = concurrentProfile.backProfile; concurrencySupported = true; await LogStatus("Concurrent profile located, device supports concurrency", NotifyType.StatusMessage); } else { // There are no concurrent profiles available on this device, thus // there is not profile to select. With a lack of concurrent profile // each camera will have to be managed manually and cannot support // simultaneous streams. So we set the Video profile to null to // indicate that camera must be managed individually. mediaInitSettingsFront.VideoProfile = null; mediaInitSettingsBack.VideoProfile = null; await LogStatus("No Concurrent profiles located, device does not support concurrency", NotifyType.ErrorMessage); } await LogStatusToOutputBox("Initializing Front camera settings"); await mediaCaptureFront.InitializeAsync(mediaInitSettingsFront); if (concurrencySupported) { await LogStatusToOutputBox("Device supports concurrency, initializing Back camera settings"); // Only initialize the back camera if concurrency is available. Otherwise, // we can only use one camera at a time (which in this case will be the front // camera). await mediaCaptureBack.InitializeAsync(mediaInitSettingsBack); } }