Skip to content

Commit

Permalink
Bugfix: No track info displayed while context menu is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
philippn committed Oct 3, 2014
1 parent 948193e commit 839a74b
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions NowPlayingKiosk/SpotifyNowPlayingTrackInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,49 @@ namespace NowPlayingKiosk
{
public class SpotifyNowPlayingTrackInfoProvider : NowPlayingTrackInfoProvider
{
private TrackInfo lastPlayed;

public TrackInfo WhatIsNowPlaying()
{
// Get the process
Process[] processList = Process.GetProcessesByName("spotify");

string windowTitle = null;
string wantedPrefix = "Spotify - ";
foreach (Process process in processList)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle) && process.MainWindowTitle.StartsWith(wantedPrefix))
if (!String.IsNullOrEmpty(process.MainWindowTitle) && process.MainWindowTitle.Equals("Spotify"))
{
windowTitle = process.MainWindowTitle.Substring(wantedPrefix.Length);
// Nothing playing right now
lastPlayed = null;
return null;
}
}
else if (!String.IsNullOrEmpty(process.MainWindowTitle) && process.MainWindowTitle.StartsWith(wantedPrefix))
{
// Spotify is playing something
string windowTitle = process.MainWindowTitle.Substring(wantedPrefix.Length);
TrackInfo nowPlaying = null;
if (windowTitle != null)
{
// For example "Foo Fighters – Monkey Wrench"
int idx = windowTitle.IndexOf('–');
if (idx != -1)
{
string artist = windowTitle.Substring(0, idx).Trim();
string title = windowTitle.Substring(idx + 1).Trim();
nowPlaying = new TrackInfo(artist, title);
}
}

TrackInfo nowPlaying = null;
if (windowTitle != null)
{
// For example "Foo Fighters – Monkey Wrench"
int idx = windowTitle.IndexOf('–');
if (idx != -1)
lastPlayed = nowPlaying;
return nowPlaying;
}
else if (String.IsNullOrEmpty(process.MainWindowTitle))
{
string artist = windowTitle.Substring(0, idx).Trim();
string title = windowTitle.Substring(idx + 1).Trim();
nowPlaying = new TrackInfo(artist, title);
return lastPlayed;
}
}

return nowPlaying;
return null;
}
}
}

0 comments on commit 839a74b

Please sign in to comment.