Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Improve Spotify title detection
Browse files Browse the repository at this point in the history
Spotify re-added the title of the currently playing track to the window title bar in a recent update. Title detection has been updated for the new redesign that spawns several processes of which one is the UI process with the title.
  • Loading branch information
protyposis committed Jun 22, 2015
1 parent 5f991a5 commit 230a8dc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions LocalAudioBroadcast/Metadata/Spotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace LocalAudioBroadcast.Metadata {
class Spotify : ITrackInfoProvider {

// Order if the titles is important, most specific (longest) title must come first
private static string[] SPOTIFY_TITLES = { "Spotify Premium", "Spotify" };
private static string[] SPOTIFY_TITLES = { "Spotify Premium", "Spotify", "" };
private const string SPOTIFY_TITLE_SEPARATOR = "";

private Process spotifyProcess;
Expand All @@ -39,13 +39,17 @@ class Spotify : ITrackInfoProvider {
public bool UpdateSpotifyProcess() {
if (spotifyProcess == null || spotifyProcess.HasExited) {
Process[] processes = Process.GetProcessesByName("spotify");
if (processes.Length > 0) {
spotifyProcess = processes[0];
return true;
}
else {
return false;

// Since Spotify's UI refresh in 2014 (v1.0), it spawns multiple processes
// and we need to search for the GUI process
foreach (var process in processes) {
if (process.MainWindowHandle != IntPtr.Zero) {
spotifyProcess = process;
return true;
}
}

return false;
}

spotifyProcess.Refresh();
Expand All @@ -62,7 +66,9 @@ public string Title {
foreach(string st in SPOTIFY_TITLES) {
if (title.StartsWith(st)) {
spotifyTitle = st;
spotifyTitlePrefix = st + SPOTIFY_TITLE_SEPARATOR;
if (st != String.Empty) {
spotifyTitlePrefix = st + SPOTIFY_TITLE_SEPARATOR;
}
break;
}
}
Expand Down

0 comments on commit 230a8dc

Please sign in to comment.