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

Commit 230a8dc

Browse files
committed
Improve Spotify title detection
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.
1 parent 5f991a5 commit 230a8dc

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

LocalAudioBroadcast/Metadata/Spotify.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace LocalAudioBroadcast.Metadata {
2727
class Spotify : ITrackInfoProvider {
2828

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

3333
private Process spotifyProcess;
@@ -39,13 +39,17 @@ class Spotify : ITrackInfoProvider {
3939
public bool UpdateSpotifyProcess() {
4040
if (spotifyProcess == null || spotifyProcess.HasExited) {
4141
Process[] processes = Process.GetProcessesByName("spotify");
42-
if (processes.Length > 0) {
43-
spotifyProcess = processes[0];
44-
return true;
45-
}
46-
else {
47-
return false;
42+
43+
// Since Spotify's UI refresh in 2014 (v1.0), it spawns multiple processes
44+
// and we need to search for the GUI process
45+
foreach (var process in processes) {
46+
if (process.MainWindowHandle != IntPtr.Zero) {
47+
spotifyProcess = process;
48+
return true;
49+
}
4850
}
51+
52+
return false;
4953
}
5054

5155
spotifyProcess.Refresh();
@@ -62,7 +66,9 @@ public string Title {
6266
foreach(string st in SPOTIFY_TITLES) {
6367
if (title.StartsWith(st)) {
6468
spotifyTitle = st;
65-
spotifyTitlePrefix = st + SPOTIFY_TITLE_SEPARATOR;
69+
if (st != String.Empty) {
70+
spotifyTitlePrefix = st + SPOTIFY_TITLE_SEPARATOR;
71+
}
6672
break;
6773
}
6874
}

0 commit comments

Comments
 (0)