1

I want to get the current song name that is being played by spotify desktop. Is there any api for doing this?

Optimally I would like something like:

string song = spotify.GetSong();

in c++ or c#. I can only seem to find the old libspotify api although it seems to no longer be a usable.

Cjen1
  • 1,826
  • 3
  • 17
  • 47

1 Answers1

3

I don't know if you can do it via the API, but I use the following code to return spotifys window title (Artist - Track)

public string GetSpotifyTrackInfo()
    {
        var proc = Process.GetProcessesByName("Spotify").FirstOrDefault(p =>!string.IsNullOrWhiteSpace(p.MainWindowTitle));

        if (proc == null)
        {
            return "Spotify is not running!";
        }

        if (string.Equals(proc.MainWindowTitle, "Spotify", StringComparison.InvariantCultureIgnoreCase))
        {
            return "Paused";
        }
        return proc.MainWindowTitle;
    }
Gruhlum
  • 67
  • 6