Пример #1
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        ///
        /// We will enable/disable parts of the UI if the device doesn't support it.
        /// </summary>
        /// <param name="eventArgs">Event data that describes how this page was reached. The Parameter
        /// property is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            Console.WriteLine("AAAA1");


            // Attach a handler to process the received advertisement.
            // The watcher cannot be started without a Received handler attached
            watcher.Received += OnAdvertisementReceived;

            // Attach a handler to process watcher stopping due to various conditions,
            // such as the Bluetooth radio turning off or the Stop method was called
            watcher.Stopped += OnAdvertisementWatcherStopped;

            // Attach handlers for suspension to stop the watcher when the App is suspended.
            App.Current.Suspending += App_Suspending;
            App.Current.Resuming   += App_Resuming;



            var audioDeviceCollection = await DeviceInformation.FindAllAsync(AudioPlaybackConnection.GetDeviceSelector(), null);

            // initAudioWatcher();

            rootPage.NotifyUser("Press Run to start watcher." + " " + audioDeviceCollection.Count + "  audio device found", NotifyType.StatusMessage);
        }
        private void MainGrid_Loaded(object sender, RoutedEventArgs e)
        {
            audioPlaybackConnections = new Dictionary <string, AudioPlaybackConnection>();

            // Start watching for paired Bluetooth devices.
            this.deviceWatcher = DeviceInformation.CreateWatcher(AudioPlaybackConnection.GetDeviceSelector());

            // Register event handlers before starting the watcher.
            this.deviceWatcher.Added   += this.DeviceWatcher_Added;
            this.deviceWatcher.Removed += this.DeviceWatcher_Removed;

            this.deviceWatcher.Start();
        }