private AudioCaptureControl() { this.mediaCaptureSemaphore = new SemaphoreSlim(1, 1); // We will query and monitor the microphone capability for audio input; the call to RequestAccessAsync needs to occur once we've // created a page so it can pop a consent prompt. this.MicrophoneCapability = AppCapability.Create("microphone"); this.MicrophoneCapability.AccessChanged += (capability, args) => { if (capability.CheckAccess() == AppCapabilityAccessStatus.Allowed) { _ = this.StartVolumePollingAsync(); } }; // We'll also monitor the audio input devices available on the system. This allows clear feedback to users when no device is connected // as well as responsiveness to devices being added or removed. this.captureDeviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.AudioCapture); this.captureDeviceWatcher.Added += async(s, e) => await this.OnAudioCaptureDevicesChangedAsync(); this.captureDeviceWatcher.Removed += async(s, e) => await this.OnAudioCaptureDevicesChangedAsync(); this.captureDeviceWatcher.Updated += async(s, e) => await this.OnAudioCaptureDevicesChangedAsync(); this.enumerationCompletedEvent = new ManualResetEventSlim(false); this.captureDeviceWatcher.EnumerationCompleted += (s, e) => { this.firstEnumerationCompleted = true; this.enumerationCompletedEvent.Set(); }; this.captureDeviceWatcher.Start(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Specify which capability we want to query/monitor. locationCapability = AppCapability.Create("location"); // Register a handler to be called when access changes. locationCapability.AccessChanged += OnCapabilityAccessChanged; // Update UI to match current access. UpdateCapabilityStatus(); }