private void OnExecuteInitializeCommand() { Task.Run(async() => { var settings = new MediaCaptureSettingsDTO(); await this.ExecuteInitialize(settings); }); }
protected override async Task ExecuteInitialize(MediaCaptureSettingsDTO settings) { try { await base.ExecuteInitialize(settings); } catch (Exception) { // TODO: Raise an interaction event on the view model to tell the view to display an error... } }
protected virtual async Task ExecuteInitialize(MediaCaptureSettingsDTO settings) { try { // TODO: Grab the settings from the user to allow for a more dynamic experience... For now we'll go with the defaults... await this.mediaCaptureController.InitializeAsync(settings); } catch (Exception) { // TODO: Raise an interaction event on the view model to tell the view to display an error... } }
protected virtual async Task ExecuteToggleInitialization() { try { if (this.mediaCaptureController.State.IsInitialized) { await this.mediaCaptureController.DeinitializeAsync(); } else { MediaCaptureSettingsDTO settings = new MediaCaptureSettingsDTO(); await this.mediaCaptureController.InitializeAsync(settings); } } catch (Exception) { // TODO: Raise an interaction event on the view model to tell the view to display an error... } }
public async Task InitializeAsync(MediaCaptureSettingsDTO settings) { lock (this.dataProtector) { if (this.mediaCaptureState.IsInitialized) { // TODO: Is this too heavy handed to throw an exception here? throw new InvalidOperationException("Media Capture Manager is already initialized..."); } if (this.mediaCaptureState.IsDeinitializing) { throw new InvalidOperationException("Media Capture Manager is currently deinitializing..."); } } // Reset the state of the object before attempting to initialize it... // await this.DeinitializeAsync(); ////////////////////////////////////////////////////////////////////////////////////////////////// // Update the state ////////////////////////////////////////////////////////////////////////////////////////////////// lock (this.dataProtector) { this.mediaCaptureState.IsInitializing = true; this.mediaCaptureState.IsInitializeFailed = false; } // Fire Update Event await this.FireMediaCaptureUpdatedEvent(); // TODO: How do we hanlde an excpetion in the MediaCapture call... Will an exception thrown in that method result in the catch block being executed // here? Assuming for the moment that wrapping the MediaCapture methods in a try/catch will work... Need to do more research... try { var mediaCaptureInitSettings = new MediaCaptureInitializationSettings(); if (settings != null) { mediaCaptureInitSettings.AudioDeviceId = settings.AudioDeviceId; mediaCaptureInitSettings.VideoDeviceId = settings.VideoDeviceId; switch (settings.CaptureMode) { case CaptureModeEnum.AudioAndVideo: mediaCaptureInitSettings.StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo; break; case CaptureModeEnum.Audio: mediaCaptureInitSettings.StreamingCaptureMode = StreamingCaptureMode.Audio; break; case CaptureModeEnum.Video: mediaCaptureInitSettings.StreamingCaptureMode = StreamingCaptureMode.Video; break; } } // Initialize Media Capture Instance await this.dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await this.mediaCapture.InitializeAsync(mediaCaptureInitSettings); }); // TODO: Should we subscribe to the media capture events before initializing or after? When Does the media capture failed event get called // Subscribe to Media Capture Events this.SubscribeToMediaCaptureEvents(); ////////////////////////////////////////////////////////////////////////////////////////////////// // Update the state ////////////////////////////////////////////////////////////////////////////////////////////////// lock (this.dataProtector) { this.mediaCaptureState.IsInitialized = true; this.mediaCaptureState.IsInitializing = false; this.mediaCaptureState.IsDeinitializing = false; } } catch (Exception) { // Deinitialize to reset the instance state... await this.DeinitializeAsync(); ////////////////////////////////////////////////////////////////////////////////////////////////// // Update the state ////////////////////////////////////////////////////////////////////////////////////////////////// lock (this.dataProtector) { this.mediaCaptureState.IsInitializeFailed = true; } } finally { // TODO: Will this execute after all the await return in the try block? Need to test... // Fire Update Event await this.FireMediaCaptureUpdatedEvent(); } }