Displaying Songs from Last.fm

To view all of my codes for these various scrobbling trinkets that display your music, visit this collection on Code Pen. I was inspired by examining code written by the amazing Prashant Shrestha. You can find his own version here.

Last.fm is a service that allows you to aggregate what you’re listening to across multiple platforms, sharing recommendations with friends and discovering new music. Before Halloween of 2024, I had only the faintest clue about it. Guess what, though? Using Last.fm, you can display what you’re listening to (on Spotify or elsewhere, apparently) on your website. This alone was worth signing up for me, so I did, and hooked my Spotify account into the service. I’ll probably use it in some other way later.

You can use Last.fm's API key, if you create one, to display your music on the web. You can follow the instructions given by Last.fm for doing this. It really boils down to creating a Last.fm account, linking it into your music service of choice, then requesting an API key here. You will notice a lot of fields in that form on the page I just linked, but really, you need only give your "application" a name of your choice, and it'll generate and work.

Once you have your API key, you can use Javascript to share your music! After looking at existing last.fm display methods, I made several versions of my own. They suit my purposes, and you might find them interesting too. I thought I’d share them here in case you’d like to play with them. I tried my hardest to make them easy to customize (mostly for myself, naturally) later on, and to prepare them to handle as much of the process as possible. They’re still probably not that good, but my husband always says that if it works, it’s not too bad, right?

These trinkets all make ample usage of jQuery and will not function without it, so be sure to include the following line (or another link to jQuery) just before your </body> tag:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

I’ve made two scrobbling trinkets.

The first pulls the most recently played song and displays that, with the artist and album cover. It would work well in a sidebar. I made a vanilla version without the album cover, too.

The second allows you to create a list (up to I believe forty songs) of your most recent tracks, their artists and their covers. There is a version without album covers, which exports the results as a simple ordered list, as well.

I certainly recommend you also visit the tutorial I used to get a handle on this, right here, by Prashant Shrestha.

Please note: I went ahead and left my own username and API key for Last.fm listed in the Code Pen examples given below to show how it works. I see no harm in doing this given that it's already running on this site in the sidebar, after all. That said, if it appears that the titles of the songs or artists names are random Cyrillic characters, it isn't a glitch. I just listen to a lot of Russian rap and hiphop, so that often appears.

Sounds of the Now: Single Song

See this and play with it on on Code Pen

CSS

HTML

Javascript

Sounds of the Now: Single Song Simplified

See this and play with it on Code Pen.

HTML

Javascript

Sounds of Now: Recent List

See this and play with it on Code Pen.

CSS

HTML

Javascript

Sounds of the Now: Simplified Recent List

See this and play with it on Code Pen.

HTML

Javascript