private void UpdateSpotifyTrackInformation_Elapsed(object sender, ElapsedEventArgs e) { // Check for interval change if (updateSpotifyTrackInfo.Interval != Global.updateSpotifyTrackInfoInterval) { updateSpotifyTrackInfo.Interval = Global.updateSpotifyTrackInfoInterval; Global.debugConsole?.WriteLine("Interval for timer updateSpotifyTrackInfo updated to " + Global.updateSpotifyTrackInfoInterval + "ms"); } // Ensure Spotify is running otherwise reset. CheckForSpotifyInstance(); if (this.spotifyRunning) { // Get Currently Playing JSON from API. string downloadedJson = this.DownloadJson(this.spotifyAPICurrentlyPlayingURL, SpotifyAddressContactType.API); if (!string.IsNullOrEmpty(downloadedJson)) { // Parse Json dynamic jsonSummary = SimpleJson.DeserializeObject(downloadedJson); // Is track currently playing? if ((bool)jsonSummary.is_playing) { // Is this a new track? SpotifyTrack newTrack = new SpotifyTrack(jsonSummary); if (newTrack.ToString() != currentPlayingTrack?.ToString()) { // Update last played track Global.IsTextOverriden = false; this.lastPlayedTrack = this.currentPlayingTrack; this.currentPlayingTrack = newTrack; //ResetUpdateAuthTokenTimer(); Global.debugConsole?.WriteLine("Now playing: " + currentPlayingTrack.ToString()); } else { RequestReset(ResetReason.NotNewSong); } } else { RequestReset(ResetReason.SpotifyPaused); } } else { RequestReset(ResetReason.InvalidJson); } } else { RequestReset(ResetReason.SpotifyNotLaunched); } }
private void AddTrackToHistory(SpotifyTrack track) { if (track == null || track.id == lastHistoryTrackAdded?.id) { return; } // Track history menu ToolStripMenuItemSpotifyTrack toolStripMenuItem = new ToolStripMenuItemSpotifyTrack { Size = new System.Drawing.Size(180, 22), Tag = track, Text = track.fullTitle, TextAlign = System.Drawing.ContentAlignment.MiddleLeft }; // Copy track link menu ToolStripMenuItemSpotifyTrack toolStripMenuItem_CopyLink = new ToolStripMenuItemSpotifyTrack { Enabled = true, Name = "toolStripMenuItem_CopyLink", Size = new System.Drawing.Size(208, 22), Tag = track, Text = "Copy link", ToolTipText = "Copies Spotify link to your clipboard.", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }; toolStripMenuItem_CopyLink.MouseClick += new MouseEventHandler(TrackHistoryClick_CopyLink); // Copy track full title menu ToolStripMenuItemSpotifyTrack toolStripMenuItem_CopyFullTitle = new ToolStripMenuItemSpotifyTrack { Enabled = true, Name = "toolStripMenuItem_CopyFullTitle", Size = new System.Drawing.Size(208, 22), Tag = track, Text = "Copy full title", ToolTipText = "Copies song name and artists to your clipboard.", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }; toolStripMenuItem_CopyFullTitle.MouseClick += new MouseEventHandler(TrackHistoryClick_CopyFullTitle); // Add the "Copy track" menus to our Track History menu toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItem_CopyLink, toolStripMenuItem_CopyFullTitle }); // Add new Track History item to the list. Global.debugConsole?.WriteLine("Adding track to history: " + track.fullTitle); lastHistoryTrackAdded = track; AddDropDownItemsToMenu(toolStripMenuItem); }
private void TrackHistoryClick_CopyFullTitle(object sender, MouseEventArgs e) { // Copy the track's full title to clipboard. The SpotifyTrack is stored in the Tag property of the control. ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender; SpotifyTrack track = (SpotifyTrack)toolStripMenuItem.Tag; if (!string.IsNullOrEmpty(track.fullTitle)) { Clipboard.SetText(track.fullTitle); Global.debugConsole?.WriteLine("Copied track FullTitle - " + track.fullTitle); } }
private void RequestReset(ResetReason resetReason) { switch (resetReason) { case ResetReason.SpotifyNotLaunched: Global.debugConsole?.WriteLine("Reset requested. Reason: Spotify is not launched."); this.spotifyRunning = false; this.spotifyHandle = IntPtr.Zero; break; case ResetReason.SpotifyPaused: Global.debugConsole?.WriteLine("Reset requested. Reason: Spotify is paused."); this.spotifyRunning = false; this.spotifyHandle = IntPtr.Zero; if (!Global.IsTextOverriden) { this.CurrentPlayingTrack = null; } break; case ResetReason.NotNewSong: Global.debugConsole?.WriteLine("Reset requested. Reason: Current song playing is not new."); this.spotifyRunning = false; this.spotifyHandle = IntPtr.Zero; break; case ResetReason.InvalidJson: Global.debugConsole?.WriteLine("Reset requested. Reason: Invalid Json."); this.spotifyRunning = false; this.spotifyHandle = IntPtr.Zero; break; case ResetReason.ForceUpdateRequested: Global.debugConsole?.WriteLine("Reset requested. Reason: Force update requested by user."); this.spotifyRunning = false; this.spotifyHandle = IntPtr.Zero; //this.refreshToken = String.Empty; //this.authorizationToken = String.Empty; ResetUpdateSpotifyTrackInformationTimer(); //ResetUpdateAuthTokenTimer(); break; default: break; } }
private void UpdateCurrentTrackPlayingTimer_Elapsed(object sender, ElapsedEventArgs e) { // Check if the stored current playing track is different than the current if (this.CurrentPlayingTrack != Global.spotify?.CurrentPlayingTrack) { this.CurrentPlayingTrack = Global.spotify.CurrentPlayingTrack; if (this.CurrentPlayingTrack == null) { SetNotifyIconText("Snip For Mammal"); WriteToSnipFile(String.Empty); } else { SetNotifyIconText(this.CurrentPlayingTrack.fullTitle); AddTrackToHistory(this.CurrentPlayingTrack); WriteToSnipFile(this.CurrentPlayingTrack.fullTitle); } } }
public void CustomTrack(string text) { //SpotifyTrack customTrack = new SpotifyTrack(string.Empty, text, string.Empty, string.Empty); Global.debugConsole.WriteLine("Setting custom track: " + text); this.CurrentPlayingTrack = new SpotifyTrack(text); }