private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (ClosingConfirmation())
     {
         e.Cancel = true;
         MinimizetoTaskbar();
         return;
     }
     DiscordRPC.Shutdown();
 }
Beispiel #2
0
 public void InitializeDiscordRichPresence()
 {
     _spotify.Connect();
     _spotify.ListenForEvents    = true;
     _spotify.OnTrackChange     += _spotify_OnTrackChange;
     _spotify.OnPlayStateChange += _spotify_OnPlayStateChange;
     _spotify.OnTrackTimeChange += _spotify_OnTrackTimeChange;
     DiscordRPC.EventHandlers handlers = new DiscordRPC.EventHandlers();
     handlers.readyCallback        += new DiscordRPC.ReadyCallback(ReadyCallback);
     handlers.disconnectedCallback += new DiscordRPC.DisconnectedCallback(DisconnectedCallback);
     handlers.errorCallback        += new DiscordRPC.ErrorCallback(ErrorCallback);
     handlers.joinCallback         += new DiscordRPC.JoinCallback(JoinCallback);
     handlers.spectateCallback     += new DiscordRPC.SpectateCallback(SpectateCallback);
     handlers.requestCallback      += new DiscordRPC.RequestCallback(RequestCallback);
     DiscordRPC.Initialize("385159254589571073", ref handlers, true, "");
     Presence = new DiscordRPC.RichPresence
     {
         largeImageKey = "spotify_logo_l"
     };
     UpdateRPC();
 }
Beispiel #3
0
        internal void UpdateRPC()
        {
            status = _spotify.GetStatus();
            string trackName;
            string artistName;

            try
            {
                trackName  = status.Track.TrackResource.Name;
                artistName = status.Track.ArtistResource.Name;
            }
            //Most likely an Ad
            catch (Exception)
            {
                trackName  = "Advert";
                artistName = "";
            }


            if (status.Track.TrackResource.Name != null && !status.Track.IsAd())
            {
                Presence.state = "🎵 " + trackName;
                if (status.Playing)
                {
                    Presence.smallImageKey  = "play";
                    Presence.smallImageText = "Playing";
                    Presence.startTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                }
                else
                {
                    Presence.smallImageKey  = "pause";
                    Presence.smallImageText = "Paused";
                    Presence.startTimestamp = 0;
                }
                Presence.details = "💽" + artistName;
                DiscordRPC.UpdatePresence(ref Presence);
            }
        }
 private void shutdownRichPresence_Click(object sender, RoutedEventArgs e)
 {
     DiscordRPC.Shutdown();
 }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     DiscordRPC.Shutdown();
     StartRichPresence();
 }