Пример #1
0
        public async Task <ZoneVolume> GetVolume()
        {
            var isMuteActionResult =
                await
                CurrentCoordinator.MediaRenderer.RenderingControl1Service.GetMute(0, AargtypeMuteChannelEnum.Master).ConfigureAwait(false);

            if (isMuteActionResult.Exception != null)
            {
                return(new ZoneVolume(null, new ZoneMute(null)));
            }

            var zoneMute = new ZoneMute(isMuteActionResult.Result);

            ActionResult volumeActionResult =
                await CurrentCoordinator.MediaRenderer.RenderingControl1Service.GetVolume(0,
                                                                                          AargtypeChannelEnum.Master);

            if (volumeActionResult.Exception != null)
            {
                return(new ZoneVolume(null, new ZoneMute(null)));
            }

            var zoneVolume = new ZoneVolume(volumeActionResult.Result, zoneMute);

            return(zoneVolume);
        }
Пример #2
0
        private async Task Poll()
        {
            while (CurrentCoordinator != null)
            {
                var sw = new Stopwatch();
                sw.Start();

                var volume = await GetVolume();

                var positionInfo = await GetPositionInfo();

                var transportState = await GetTransportInfo();

                if (_volume == null)
                {
                    Debug.WriteLine("Volume = null");
                }
                else
                {
                    Debug.WriteLine("volume: {0}, ismuted: {1}", volume.Volume, volume.IsMuted);
                }
                // volume
                if (_volume == null ||
                    _volume.Volume != volume.Volume ||
                    _volume.IsMuted != volume.IsMuted)
                {
                    _volume = volume;
                    _messageBus.Send(new VolumeChangedMessage {
                        ZoneVolume = volume
                    });
                }

                // position info
                if (_positionInfo == null ||
                    _positionInfo.Track.Title != positionInfo.Track.Title ||
                    _positionInfo.Track.AlbumTitle != positionInfo.Track.Artist ||
                    _positionInfo.Track.ImageUri != positionInfo.Track.ImageUri)
                {
                    _positionInfo = positionInfo;
                    _messageBus.Send(new PositionInfoChangedMessage {
                        PositionInfo = positionInfo
                    });
                }

                // transport info
                if (transportState.TransportState != CurrentTransportState)
                {
                    CurrentTransportState = transportState.TransportState;
                    _messageBus.Send(new TransportStateChangedMessage {
                        TransportState = transportState.TransportState
                    });
                }

                sw.Stop();
                Debug.WriteLine("ZoneService poll {0} ms", sw.ElapsedMilliseconds);
                var timeout = 1000 - (int)sw.ElapsedMilliseconds;
                if (timeout < 0)
                {
                    timeout = 1000;
                }

                await Task.Delay(timeout)
                .ConfigureAwait(false);
            }
        }
Пример #3
0
        private void SetVolumeUri(ZoneVolume zoneVolume)
        {
            int volume = zoneVolume.IsMuted ? 0 : zoneVolume.Volume;

            SetVolumeUri(volume);
        }