コード例 #1
0
        private void IPCClient_Disconnected(object sender, EventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                Visibility = Visibility.Hidden;

                var deskband = DeskBand.GetInstance();
                deskband.ShowDeskBand(false);
            }, CancellationToken.None, TaskCreationOptions.None, uiContext);
        }
コード例 #2
0
        private void IPCClient_MessageReceived(object sender, XmlNode messageNode)
        {
            Task.Factory.StartNew(() =>
            {
                Visibility = Visibility.Visible;

                var deskband = DeskBand.GetInstance();
                deskband.ShowDeskBand(true);

                switch (messageNode.Attributes["action"].InnerText)
                {
                case "playbackStateChanged":
                    doNotTriggerEvent = true;

                    var hasTrack = messageNode.SelectSingleNode("hasTrack").InnerText == "true";

                    if (hasTrack)
                    {
                        Title     = messageNode.SelectSingleNode("title").InnerText;
                        Duration  = long.Parse(messageNode.SelectSingleNode("duration").InnerText);
                        IsPlaying = messageNode.SelectSingleNode("playing").InnerText == "true";

                        sliderPosition.Value     = long.Parse(messageNode.SelectSingleNode("position").InnerText);
                        sliderPosition.IsEnabled = true;

                        // load artwork
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource   = new Uri(messageNode.SelectSingleNode("artwork").InnerText, UriKind.Absolute);
                        bitmap.CacheOption = BitmapCacheOption.Default;
                        bitmap.EndInit();

                        imageArtwork.Source = bitmap;
                    }
                    else
                    {
                        Title     = string.Empty;
                        Duration  = 1;
                        IsPlaying = false;

                        sliderPosition.Value     = 0;
                        sliderPosition.IsEnabled = false;

                        // unload artwork
                        imageArtwork.Source = null;
                    }

                    buttonPlay.Visibility  = IsPlaying ? Visibility.Collapsed : Visibility.Visible;
                    buttonPause.Visibility = IsPlaying ? Visibility.Visible : Visibility.Collapsed;

                    doNotTriggerEvent = false;
                    break;

                case "positionChanged":
                    doNotTriggerEvent    = true;
                    sliderPosition.Value = long.Parse(messageNode.SelectSingleNode("position").InnerText);
                    doNotTriggerEvent    = false;
                    break;

                case "volumeChanged":
                    doNotTriggerEvent  = true;
                    sliderVolume.Value = int.Parse(messageNode.SelectSingleNode("volume").InnerText);
                    doNotTriggerEvent  = false;
                    break;
                }
            }, CancellationToken.None, TaskCreationOptions.None, uiContext);
        }