Пример #1
0
        /// <summary>Handles the devices changed event.</summary>
        /// <param name="data">The data.</param>
        private void HandleDevicesChanged(DevicesContainer data)
        {
            this.isReadingEvents = true;

            if (data.Devices == null)
            {
                return;
            }

            this.Devices = new ObservableCollection <DeviceComboBoxItemViewModel>(
                data.Devices.Select(
                    o =>
            {
                var viewModel = this.container.Resolve <DeviceComboBoxItemViewModel>();
                viewModel.AttachedDataModel = o;
                return(viewModel);
            }).ToList());

            this.SelectedDevice = this.Devices.FirstOrDefault(o => o.IsActive);

            if (!this.VolumeHasFocus)
            {
                this.Volume = this.SelectedDevice?.VolumePercent ?? 0;
            }

            this.UpdateIsLocalDeviceActive();

            this.isReadingEvents = false;
        }
Пример #2
0
        /// <summary>Updates continuously.</summary>
        private async void UpdateContinuously()
        {
            while (this.running)
            {
                var newDevicesContainer = await this.api.Player.GetAvailableDevices();

                if (!this.devicesEqualityComparer.Equals(this.devicesContainer, newDevicesContainer))
                {
                    this.eventAggregator.GetEvent <DevicesChangedEvent>().Publish(newDevicesContainer);
                    this.devicesContainer = newDevicesContainer;
                }

                var newCurrentlyPlayingContext = await this.api.Player.GetCurrentlyPlayingContext();

                if (!this.playingEqualityComparer.Equals(this.currentlyPlayingContext, newCurrentlyPlayingContext))
                {
                    this.eventAggregator.GetEvent <CurrentlyPlayingContextChangedEvent>().Publish(newCurrentlyPlayingContext);
                    this.currentlyPlayingContext = newCurrentlyPlayingContext;

                    await this.UpdateCurrentlyPlayingImage();
                }

                await Task.Delay(TimeSpan.FromSeconds(1));
            }
        }